2017/05/23

git常用配置


全局配置名称和邮箱

git config --global user.name "输入你的用户名"
git config --global user.email "输入你的邮箱"

配置完成后会在用户根目录下生成配置文件 ~/.gitconfig ,我们也可以通过 ``git config --list 查看当前以及配置好的内容


查看本地分支:git branch

查看远程分支:git branch -r

查看所有分支:git branch -a


检索远程的 origin/branch01 分支,在本地起名为 local_branch01 分支,并将本地工作环境切换到的 local_branch01 分支

git checkout -b local_branch01 origin/branch01

git 配置ssh

默认使用用户 ~/.ssh/id_rsa 作为秘钥,将 ~/.ssh/id_rsa.pub 作为公钥配置到远程git仓库即可使用,如果需要配置不同的秘钥,则可以在 ~/.ssh/config 下进行编辑配置 eg:

Host    server.github.com
    HostName    github.com
    User    git
    IdentityFile    ~/.ssh/id_rsa

Host    blog.coding.com
    HostName    coding.com
    User    git
    IdentityFile ~/.ssh/coding_rsa

详细的生成 ssh key 和配置可以查看之前写的一篇文章: http://www.yangxg.com/blog/2368788747.html


git 提交流程

git add .
git commit -am "提交说明描述"
git push

git fetch和pull的区别:http://www.jianshu.com/p/d265f7763a3a


git rebase:http://blog.csdn.net/hudashi/article/details/7664631/


将本地版本回退到和远程的一样:git reset --hard origin/master