python git切换分支_切换到哪个分支,本地就下载了哪个分支的代码嘛?

如果是大家一起协作的情况,可能其他人推了其他分支到中央仓库,这时候你本地是看不到的。

比如原来只有master分支,另外一个人推送了f1分支。

这时候在你的本地,

λ git branch -a

* master

remotes/origin/HEAD -> origin/master

remotes/origin/master

直接执行切换分支到f1,

λ git checkout f1

error: pathspec 'f1' did not match any file(s) known to git.

当然是不行的啦。

那么应该怎么做呢?

你可以把中央的分支信息取下来

λ git fetch origin

remote: Counting objects: 3, done.

remote: Compressing objects: 100% (2/2), done.

remote: Total 3 (delta 1), reused 0 (delta 0)

Unpacking objects: 100% (3/3), done.

From https://git.coding.net/xxx/xxx

* [new branch] f1 -> origin/f1

λ git branch -a

* master

remotes/origin/HEAD -> origin/master

remotes/origin/f1

remotes/origin/master

这样你就能愉快地切换分支了

λ git checkout f1

Branch f1 set up to track remote branch f1 from origin.

Switched to a new branch 'f1'

此时你已经在f1分支了,

λ git branch -a

* f1

master

remotes/origin/HEAD -> origin/master

remotes/origin/f1

remotes/origin/master

*在前面表示本地当前所指向的分支。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值