1.查看远程仓库:git remote -v
2.查看本地分支:git branch
3.添加远程仓库:git remote add []
4.从远程仓库获取最新版本代码:git fetch tang master:temp(从远程的tang仓库中的master分支下载到本地的master分支,并新建一个temp分支)
注意:不建议使用pull拉取最新代码,因为pull拉取下来后会自动和本地分支合并
获取最新版本有两种 :拉取(pull)和获取(fetch)
- git pull 从远程拉取最新版本 到本地 自动合并 merge git pull origin master
- git fetch 从远程获取最新版本 到本地 不会自动合并 merge git fetch origin master
实际使用中 使用git fetch 更安全 在merge之前可以看清楚 更新情况 再决定是否合并
5.查看temp分支与本地原有分支的不同:git diff temp
6.将temp分支和本地的master分支合并:git merge temp
如果需要删除创建的temp分支:git branch -d temp
合并出现的问题:
如果报错:fatal: refusing to merge unrelated histories
则尝试输入:git merge temp --allow-unrelated-histories
如果继续报错:CONFLICT (add/add): Merge conflict in README.md
则需要先解决冲突
7.全局配置和单个仓库的用户名邮箱配置
一般都配置了一个全局的用户名和邮箱
#全局用户名和邮箱
$ git config --global user.name "github's Name"
$ git config --global user.email "[email protected]"
#查看
$ git config --list
执行git操作默认会使用全局的,用户名和邮箱。其实也可以针对公司的项目, 在项目根目录下进行单独配置
$ cd {
项目根目录}
$ git config user.name "gitlab's Name"
$ git config user.email "[email protected]"
#查看当前配置, 在当前项目下面查看的配置是全局配置+当前项目的配置, 使用的时候会优先使用当前项目的配置
git config --list