天天看点

git基本命令、基本概念github基本命令、基本概念

目录

  • github基本命令、基本概念
    • 0. 假设你已经安装好了git
    • 1. 新建仓库
    • 2. 本地文件夹关联远程仓库
    • 3. 一些常用命令

github基本命令、基本概念

0. 假设你已经安装好了git

1. 新建仓库

  • 登录网页版github,点击绿色按钮New创建一个仓库:example
    git基本命令、基本概念github基本命令、基本概念
  • 点击绿色按钮:Create
    git基本命令、基本概念github基本命令、基本概念

2. 本地文件夹关联远程仓库

  • 在本地新建一个文件夹example并进入
  • 空白处右键,选择git bash here
    git基本命令、基本概念github基本命令、基本概念
  • 输入

    git init

    进行初始化,如果电脑设置了显示隐藏文件(文件夹)则会有一个.git文件夹
    git基本命令、基本概念github基本命令、基本概念
  • 关联远程仓库有两种方式:

    -一种是https关联方式:输入命令

    git remote add origin https://github.com/[email protected]/example.git

    -另一种是ssh关联方式依次输入以下命令并一路回车:
cd ~
ssh-genkey -t rsa -C [email protected]
cat id_rsa.pub
           

第一行:进入Windows主目录,即c:\users

第二行:生成rsa公私钥对,这里一直回车就行

git基本命令、基本概念github基本命令、基本概念

第三行:此时会输出rsa公钥, 从ssh-rsa开始复制到结尾, 并粘贴到github–>settings–>ssh and gpg keys以下key字段中。Title随便起一个。

git基本命令、基本概念github基本命令、基本概念
git基本命令、基本概念github基本命令、基本概念
git remote add origin_ssh [email protected]:1130646208/example.git
           

到此关联远程仓库完成。

解释:origin 和 origin_ssh相当于是远程地址的简称替代,名字可以随便取。

3. 一些常用命令

git架构图

git基本命令、基本概念github基本命令、基本概念

用户相关

git config --list

看所有用户

git config [--global] user.name "[name]"

配置全局用户名

git config [--global] user.email "[email address]"

配置全局用户邮箱

分支相关

git branch

查看本地所有分支

git status

查看当前状态

git commit

提交

git branch -a

查看所有的分支

git branch -r

查看远程所有分支

git branch [branch-name]

新建分支但是留在当前分支

git checkout -b dev

建立一个新的本地分支dev并切换到dev

git checkout dev

切换到本地dev分支

git branch -d [branch-name]

删除名为branch-name的分支

git branch branch_0.1 master

从主分支master创建branch_0.1分支

git checkout branch_1.0/master

切换到branch_1.0/master分支

git branch -dr [remote/branch]

删除远程分支branch

提交本地相关

git add .

将文件添加到暂存区

git diff

查看尚未暂存的更新

git commit -a

提交当前repos的所有的改变

git add [file name]

添加一个文件到git index

git commit -v

当你用-v参数的时候可以看commit的差异

git commit -m "This is the message describing the commit"

添加commit信息

提交远程相关

git remote add origin [email protected]:[email protected]/example.git
           

git remote -v

查看所有远程地址和简称对应关系

git基本命令、基本概念github基本命令、基本概念

git push origin master

将本地项目给提交到服务器中的master分支

git fetch

相当于是从远程获取最新版本到本地,不会自动merge

git merge dev

将dev 合并到当前分支(当前分支即括号中蓝色的分支master)

git基本命令、基本概念github基本命令、基本概念

git pull

本地与服务器端同步相当于fetch+merge

暂时就这些, 自己找起来比较方便

参考

https://www.cnblogs.com/miracle77hp/articles/11163532.html

https://blog.csdn.net/halaoda/article/details/78661334

继续阅读