Git discard all changes and pull out of upstream

How do I get the repository up and get it to replace master? I only have one branch on my repo, which is the master, and I completely confused it, so I basically need to start from the upstream. I think init will do the job, but is there an easier way?

+112
git
Dec 08
source share
4 answers

Here (at least) there are two things that you can do here: you can postpone the remote repo or you can reset --hard to a common ancestor, and then perform an extraction that reset --hard to the last commit on the remote master.,

To be specific, here is a simple continuation of the original Nevik Rehnel answer:

 git reset --hard origin/master git pull origin master 

NOTE : using git reset --hard any uncommitted changes, and it can be easy to confuse yourself with this command if you are new to git, so make sure you have an idea of โ€‹โ€‹what it is going to do before proceeding.

+188
Dec 08
source share

and on the main server: git reset --hard origin/master

then do a cleanup using git gc (more on this in the man pages)

Update. You may also need git fetch origin (or git fetch origin master if you only want this thread); it doesn't matter if you do this before or after reset. (Thanks @ eric-walker)

+20
Dec 08
source share

You can do this in one command:

 git fetch --all && git reset --hard origin/master 

Or in a couple of commands:

 git fetch --all git reset --hard origin/master 

Note that you will lose ALL of your local changes.

+13
Sep 14 '17 at 13:42 on
source share
 git reset <hash> # you need to know the last good hash, so you can remove all your local commits git fetch upstream git checkout master git merge upstream/master git push origin master -f 

voila, now your fork is back to the same as upstream.

+4
Nov 07 '15 at
source share



All Articles