Git checkout and merge without touching working tree

后端 未结 4 2045
面向向阳花
面向向阳花 2020-11-30 00:43

Say I have a feature branch, into which I merge upstream changes prior to pushing my changes back:

git branch feature1
... [edit my code]
... [commit]
git fe         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 01:34

    [Edit] This is only a partial solution / workaround. See the actual answer by @djpohly below.

    Firstly, you can push from anywhere. Doesn't matter what you have checked out, or whether the commits you want to push are in master.

    git push REMOTE_REPO feature1:master
    

    see git help push

    Hint: git push remoteRepo localRef:remoteRef

    As for bringing master to where you are now without fiddling with your working copy... You can force it like so:

    # (while still on feature1 branch)
    git checkout -B master origin/master
    

    But this does a hard reset on master. ie it doesn't check for fast-forward.

提交回复
热议问题