Git基本应用

1、创建SSH Key

$ cd ~/.ssh
$ ssh-keygen -t rsa -C "your_email@example.com"

拷贝id_rsa.pub文件到Settings->SSH Keys->Add SSH key

2、测试

$ ssh -T git@github.com
Hi username! You've successfully authenticated, but GitHub does not
 provide shell access.

3、设置用户名和email

git config  --global user.name "your name"
git config --global user.email yourname@email_server

4、克隆

注意刚刚生成ssh key是在.ssh目录下,克隆之前记得修改路径到你的工作目录

git clone git@github.com:lgsun592/for_test.git

5、查看状态

git status

6、提交

git commit -a -m 'comment'

7、推送至服务器

将本地推送至服务器master分支

git push origin master

8、分支

git branch                         #列出本地分支,当前分支前加*
git branch -r                      #列出服务器分支
git branch -a                      #列出所有分支
git branch NEW_BRANCH_NAME         #创建新的本地分支,不切换
git checkout NEW_BRANCH_NAME       #切换分支
git push orign NEW_BRANCH_NAME     #将本地NEW_BRANCH_NAME分支推送到服务器,成为新的服务器分支
git merge NEW_BRANCH_NAME          #合并分支NEW_BRANCH_NAME到主分支

9、合并

git merge               #用于合并两个分支。
git diff                #如果有冲突,直接使用diff查看,
                        #冲突代码用<<<和>>>表示。手动修改冲突代码。
git update-index        #更新修改后的文件状态。
git commit -a -e        #提交为解决冲突而修改的代码。

更多内容可以访问:http://gitref.org/zh/basic/

原文地址:https://www.cnblogs.com/fuxinci/p/3141848.html