0


Git checkout 指令总结:切换本地和远程分支、查看本地与远程分支关系

1、切换本地分支

git checkout 本地分支

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (master)
$ git checkout zzg-master
Switched to branch 'zzg-master'
M       .idea/sonarlint/issuestore/c/4/c4287d63e4d7d93045c9448f2aeabe1a6f1fc897
M       .idea/sonarlint/issuestore/d/2/d2dd080319744a6e705bf0478f40a97a32617e02
M       .idea/sonarlint/issuestore/index.pb
A       .idea/vcs.xml
M       smart-medical-consumer-feign/src/main/java/com/zzg/controller/UserFeignController.java
Your branch is up to date with 'origin/master'.

2、切换远程分支

使用场景,本地只有分支A,远程有A和B,需要将本地分支,从A切换到B分支:

2.1 查看所有分支(包含本地分支和远程分支)

git branch -a

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (master)
$ git branch -a
* master
  zzg-master
  remotes/origin/master
  remotes/origin/zzg-master

2.2 切换分支

git checkout -b b-master origin/master #作用是checkout远程的master分支,在本地起名为b-master分支,并切换到本地的b-master分支


zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (zzg-master)
$ git checkout -b b-master origin/master
Switched to a new branch 'b-master'
M       .idea/sonarlint/issuestore/c/4/c4287d63e4d7d93045c9448f2aeabe1a6f1fc897
M       .idea/sonarlint/issuestore/d/2/d2dd080319744a6e705bf0478f40a97a32617e02
M       .idea/sonarlint/issuestore/index.pb
A       .idea/vcs.xml
M       smart-medical-consumer-feign/src/main/java/com/zzg/controller/UserFeignController.java
branch 'b-master' set up to track 'origin/master'.

3、本地分支关联远程分支

git branch --set-upstream 本地分支 origin/远程分支

温馨提示:不推荐使用指令

5.查看本地远程分支关系

git config --list

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (b-master)
$ git config --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=D:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager-core
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
[email protected]
user.name=zhouzhiwengang
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
[email protected]:zhouzhiwengang/SpringCloud-.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.zzg-master.remote=origin
branch.zzg-master.merge=refs/heads/master
branch.b-master.remote=origin
branch.b-master.merge=refs/heads/master

温馨提示:重返命令行,按q

5、删除本地分支

git branch -d 本地分支

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (master)
$ git branch -a
  b-master
* master
  zzg-master
  remotes/origin/master
  remotes/origin/zzg-master

zzg@LAPTOP-8R0KHL88 MINGW64 /e/idea_workspace/smart-medical (master)
$ git branch -d b-master
Deleted branch b-master (was ac4b488).

6、删除远程分支

git push origin --delete 远程分支
标签: Git

本文转载自: https://blog.csdn.net/zhouzhiwengang/article/details/124445493
版权归原作者 在奋斗的大道 所有, 如有侵权,请联系我们删除。

“Git checkout 指令总结:切换本地和远程分支、查看本地与远程分支关系”的评论:

还没有评论