Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
954 views
in Technique[技术] by (71.8m points)

git - Force my local master to be origin/master

I've let master and origin/master get stuck in the sidelines, and am no longer interested in the changes on that branch.

I followed these instructions to get my local master pointing to the right place Make the current git branch a master branch

 git checkout better_branch
 git merge --strategy=ours master    # keep the content of this branch, but record a merge
 git checkout master
 git merge better_branch             # fast-forward master up to the merge

which worked fine except git status gives

C:datalocalprojectsBeko2011Azure [master]> git status

# On branch master
# Your branch and 'origin/master' have diverged,
# and have 395 and 2 different commits each, respectively.
#
nothing to commit, working directory clean

so how do I now persuade origin/master (github) to reflect my master. Anything orphaned on origin/master can be safely abandoned.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To have origin/master the same as master:

git push -f origin master:master

Discussion on the parameters:

  • -f is the force flag. Normally, some checks are being applied before it's allowed to push to a branch. The -f flag turns off all checks.

  • origin is the name of the remote where to push (you could have several remotes in one repo)

  • master:master means: push my local branch master to the remote branch master. The general form is localbranch:remotebranch. Knowing this is especially handy when you want to delete a branch on the remote: in that case, you push an empty local branch to the remote, thus deleting it: git push origin :remote_branch_to_be_deleted

A more elaborate description of the parameters could be found with man git-push


Opposite direction: If you want to throw away all your changes on master and want to have it exactly the same as origin/master:

git checkout master
git reset --hard origin/master

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...