Take the 2-minute tour ×
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
add comment

3 Answers

up vote 51 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
add comment

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

git update-ref refs/heads/master origin/master
git reset --hard 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 '13 at 12:37
    
I still get Already on 'master' –  yourfriendzak Aug 21 '13 at 22:56
    
@yourfriendzak, I forgot about taking into account that you might already have master checked out before updating master. I have updated the answer to be one that should work even in that case as well. –  Alexander Bird Aug 22 '13 at 19:02
add comment

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
add comment

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.