总是忘了,写一下能记住
1.先在原来的分支git pull 确定和原来分支的内容有没有冲突,如果有冲突。重新提交,(1)git add . (2) git commit
2.查看所有分支 git branch -a
3.git checkout -b ‘your branch’ origin/ ‘your branch’
这样没啥问题的话就切过去了 然后重新pull新分支的东西就好了
总是忘了,写一下能记住
1.先在原来的分支git pull 确定和原来分支的内容有没有冲突,如果有冲突。重新提交,(1)git add . (2) git commit
2.查看所有分支 git branch -a
3.git checkout -b ‘your branch’ origin/ ‘your branch’
这样没啥问题的话就切过去了 然后重新pull新分支的东西就好了
转载于:https://www.cnblogs.com/zx-qd/p/10619671.html
Git 切换本地分支 切换远程分支
切换本地分支git checkout work1 切换到新的分支工作(不存在则会创建)
将本地已有的分支(已经存在) 和 远程分支连接
git branch --set-upstream-to=origin/master(远程分支名) work1(本地分支名)
但是如果直接本地分支与远程新建分支直接关联,git会抛出如下错误
因为Git认为这两个是毫不关联的分支,所以最好的方法是本地新建一个分支,去关联远程分支,然后拉去远程代码,然后本地合并,最后提交代码
下面命令作用是checkout远程的dev分支,在本地起名为dev分支,并切换到本地的dev分支
git checkout -b dev origin/dev
如果从未与远程仓库关联过,需要使用:
git remote add origin git@github.com:git_username/repository_name.git
注意:origin代表远程仓库 后面紧接着仓库地址
git 切换远程分支
命令:
git checkout -b 本地分支名 origin/远程分支名
例如需要切换远程的develop分支,命令:
git checkout -b develop origin/develop
-b 本地分支名 是为了关联本地分支与远程分支,这样git pull的时候不用指定远程分支,直接git pull就可以直接拉取。
1. 切换git远程分支,使用命令:git checkout -b 分支名称。
- 注意:切换远程分支一定要带伤-b 参数,只有切换本地分支的时候才不需要 -b参数,-b 的意思是 base,以当前分支为 base,新建一个名叫xxx 的分支 。如果使用 "git branch 远程分支名" 命令切换到远程服务器分支上,
则会导致如下错误提示:
You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name>这时候再使用git branch 命令查看本地分支,就会发现当前分支是在一个 叫“(HEAD detached at 远程分支名)”上。detached是游离的意思,表名当前分支是在游离状态。
2. 远程服务器新建了分支,本地无法checkout ,或者本地看不到,使用命令: git branch -r 可以查看远程分支。
如果这时候直接使用 git checkout -b xxxx 去切换到远程分支,是会报如下错误的
error: pathspec 'branch170628_foo' did not match any file(s) known to git请使用命令:git fetch 更新remote索引
取回所有分支(branch)的更新。如果只想取回特定分支的更新,可以指定分支名,例:$ git fetch <远程主机名> <分支名>
转载于:https://my.oschina.net/xuzimian/blog/3040212