用户信息配置
1 2 3 4 5
| $ git config --global user.name "Martin" $ git config --global user.email "user_name@outlook.com"
$ git config --global core.autocrlf false
|
作为身份信息,在第一次是配置就可以,后续可修改。
配置查看
1 2 3 4 5 6 7 8 9 10 11
| $ git config --global --list user.name=your_name user.email=user_name@outlook.com credential.helper=manager color.diff=auto color.status=auto color.branch=auto
$ git config --local --list $ git config --system --list
|
生成公钥,免密访问
1 2 3 4 5 6
| $ ssh-keygen -t rsa [-b 4096] -C "user_name@outlook.com"
$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.135.1 $ ssh root@192.168.135.1
$ ssh-keygen -R [IP/主机名]
|
通过ssh-keygen生成后,可以在user/.ssh
目录下看到id_rsa、id_rsa.pub文件,打开公钥id_rsa.pub,拷贝到github或gitee上的SSH公钥处,后面就可以免密推送到remote端。
新建仓库
1 2 3 4 5 6
| $ git init
$ git init [project-name]
$ git clone [url]
|
远程仓库相关操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| git remote add origin ssh://git@xxx.cn/BugFix.git
git remote -v git remote show orgin
git fetch origin master:master // git merge origin git pull origin master git pull --rebase origin master
git push git push -u origin master
git push -f origin develop_local:develop
|
本地分支与远程分支的关联跟踪
1 2 3 4 5 6 7 8 9 10 11 12 13
| 1. 从指定远程分支拉取到本地, 会自动关联 git checkout -b local_branch origin/develop
2. 手动关联 git branch --set-upstream-to=origin/develop local_branch git branch -u origin/develop local_branch
3. 解除关联 git branch --unset-upstream [local_branch] git branch -u [local_branch]
4. 查看当前关联情况 git branch -vv
|