Update **not** the current branch (in Git)

百般思念 提交于 2019-12-10 22:40:51

问题


So I am in branch feature. And I want to rebase w/ branch master.

git rebase master

And it says that feature branch is up-to-date. Of course it is because master branch hasn't changed — it is the same as in moment when I create feature branch from it.

Actually it is not. All I need is to do pull in master branch.

git checkout master
git pull
git checkout feature

My question: can't I update master branch w/o checking-out to it?

I tried from feature branch:

git pull origin master master

...but it updated feature branch (not what I wanted to) and it has commits “in furure“ in it.

Thanks in any advice! :)


回答1:


git push . origin/master:master

the dot refers to the current repository. This will stop you from doing non-fast-forward updates. If you still want to that, you can add the -f or --force options.




回答2:


If you are sure that you don't have anything on master that you want to keep you can do:

git fetch
git update-ref refs/heads/master origin/master

If you are doing this regularly, though, there is really no point in keeping your master branch. Just use the remote tracking branch (origin/master) for merges, diffs, rebases, etc. as it is updated automatically by git fetch.



来源:https://stackoverflow.com/questions/13580484/update-not-the-current-branch-in-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!