Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Can I do following in a simpler way?

git checkout origin/master
git branch -D master
git branch master
git checkout master
share|improve this question

3 Answers

up vote 34 down vote accepted

Something like:

$ git checkout master

# remember where the master was referencing to
$ git branch previous_master

# Reset master back to origin/master
$ git reset --hard origin/master

with step 2 being optional.

share|improve this answer
The most useful part for me was step 2. I found that git didn't want to point master at origin/master until there was some branch pointing at the previous master. – sidewaysmilk Aug 6 '12 at 21:12

I think even VonC's answer has complexity compared to this option:

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

git automatically logs every value of a ref (through the reflog). So after you run that command, then master@{1} refers to the previous value of master.

VonC's answer is correct, but it wastes time checkout out the old value of master into the filesystem.

If you care about orphaned objects in the repo, then you can run git gc

share|improve this answer
Sounds an interesting alternative. +1 – VonC Mar 19 at 12:37

You already are the master. What you want is to remove the remote origin so git pull doesn't do anything. So

git remote rm origin

You can then add the current repository as the origin to the remote repository if you feel like it.

NB if local is ahead of remote your solution will wipe local changes!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.