赞
踩
git branch
只能查看本地分支,如果要查看远程分支需要加上-r
选项,即git branch -r
git pull
一下才能看到远端分支$ git branch -r
origin/dev
origin/main
$ git pull
From github.com:DieSnowK/Git-Learn
* [new branch] test -> origin/test
Already up to date.
$ git branch -r
origin/dev
origin/main
origin/test
git branch -a
git branch -vv
git remote show origin
git pull
之后,本地是没有dev
分支的,需要在本地新建dev
分支,并与远端的origin/dev
分支建立联系git checkout -b branch_name origin/branch_name
git branch --set-upstream-to=origin/branch_name branch_name
main
为基准,且是最新的push
main
是最新的吗?main
分支git pull
一下git push origin branch_name
master
分支下,SnowK.txt
文件新增代码Die
和SnowK
Die
,开发者B新增SnowK
$ cat SnowK.txt Die $ git add . $ git commit -m "A push sth" [dev de4ac94] A push sth 1 file changed, 1 insertion(+) $ git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 20 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 281 bytes | 281.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To github.com:DieSnowK/Git-Learn.git 6981c9d..de4ac94 dev -> dev
$ cat SnowK.txt SnowK $ git add . $ git commit -m "B push sth" [dev 074d5ec] B push sth 1 file changed, 1 insertion(+) $ git push To github.com:DieSnowK/Git-Learn.git ! [rejected] dev -> dev (fetch first) error: failed to push some refs to 'github.com:DieSnowK/Git-Learn.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
git pull
将远端代码从origin/dev
拉取下来$ git pull remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), 261 bytes | 16.00 KiB/s, done. From github.com:DieSnowK/Git-Learn 6981c9d..de4ac94 dev -> origin/dev Auto-merging SnowK.txt CONFLICT (content): Merge conflict in SnowK.txt Automatic merge failed; fix conflicts and then commit the result. # 解决冲突ing $ cat SnowK.txt Die SnowK $ git add . $ git commit -m "solve the conflict, merge from origin/dev" [dev 10cd204] solve the conflict, merge from origin/dev $ git push Enumerating objects: 10, done. Counting objects: 100% (10/10), done. Delta compression using up to 20 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (6/6), 636 bytes | 636.00 KiB/s, done. Total 6 (delta 0), reused 0 (delta 0), pack-reused 0 To github.com:DieSnowK/Git-Learn.git de4ac94..10cd204 dev -> dev
dev
分支,已经是最新版本,但是要如何将该dev
分支合并至main
分支呢?
Pull Request(PR)
,交由审查员审核后合并main
分支,git pull
拉取下最新的main
分支$ git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
$ git pull
Already up to date.
dev
分支,合并main
分支
dev
分支解决,以避免对main
分支造成影响$ git checkout dev
Switched to branch 'dev'
Your branch is up to date with 'origin/dev'.
$ git merge main
Already up to date.
main
分支,合并dev
分支,并将main
分支推送至远端$ git checkout main Switched to branch 'main' Your branch is up to date with 'origin/main'. $ git merge dev Updating 6241400..10cd204 Fast-forward SnowK.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 SnowK.txt $ cat SnowK.txt Die SnowK $ git status On branch main Your branch is ahead of 'origin/main' by 5 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean $ git push origin main Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 To github.com:DieSnowK/Git-Learn.git 6241400..10cd204 main -> main $ git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean
dev
分支已经完成它的任务,可以删除远端和本地的dev
分支了git push origin branch-name
推送⾃⼰的修改git pull
试图合并git push origin branch-name
推送就能成功merge
进main
,最后删除分⽀Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。