远程仓库的基本操作
git clone <url>
克隆仓库- 克隆后默认把远程仓库的名字改为origin,且本地分支默认跟踪对应的远程分支
git remote
查看远程仓库名称列表git remote -v
查看带上URL的远程仓库信息git remote show <remote>
查看remote远程仓库的详细信息git remote add <remote> <url>
增加远程仓库git remote rename <old-remote-name> <new-remote-name>
重命名远程仓库git remote rm <remote>
删除远程仓库
fetch与pull
git fetch <remote>
获取remote远程仓库的更新信息git fetch --all
获取所有远程仓库的更新信息 fetch前fetch后
fetch多个远程仓库
git pull
拉取跟踪分支的更新信息,然后自动合并,相当于fetch + mergegit pull <remote> <branch>
拉取remote远程仓库的branch分支git pull <url> <branch>
只拉取一次,不把url加入远程仓库列表git push
git pull
命令,远程仓库默认名称是origin,远程仓库的名字为origin,可以省略
远程分支
- 本地的远程分支以(remote)/(branch)命名
- 本地的远程分支不可编辑
git checkout -b <branch> <remote>/<branch>
以远程分支为起点新建本地分支git checkout --track <remote-name>/<remote-branch>
以远程分支为起点新建本地分支并设置好跟踪分支git checkout --track <local-branch> <remote-name>/<remote-branch>
本地分支设置不同的分支名git branch -u <remote>/<branch>
或git branch --set-upstream-to <remote>/<branch>
设置当前分支的跟踪分支@{upstream}
或@{u}
跟踪分支的快捷方式git branch -vv
查看包含跟踪分支的分支信息
push
git push <remote> <branch>
当前分支推送更新到remote远程仓库的branch分支git push <remote> <local-branch> <remote-branch>
本地local-branch分支推送到remote远程仓库的remote-branch分支git push <remote> --delete <remote-branch>
删除远程分支- 执行
git push
假如远程仓库有新的提交,则push操作会被拒绝,必须先pull远程仓库的更新内容 - 假如pull拉取下来的更新内容与本地仓库修改的内容有冲突,则需要手动修改合并冲突,处理完再push
PREVIOUSGit分支
NEXTGit分支模型及工作流