1

I have created a fork of the master code. I have made some changes and opened a pull request, my pull request has been accepted and it is now in the master branch.

Now I just want my local branch to be exactly like the current master branch which will also include my code since it is now in the master branch.

So I do not care about any changes I have made to my branch after the pull request has been accepted.
I have tried git pull upstream master and git remote update but neither of them updates the files on my local computer that differ from the master branch. They only downloaded new files.

Herman Toothrot
  • 1,463
  • 3
  • 23
  • 53

1 Answers1

0

If you have added the original repo as a remote, this is easy:

git remote add upstream https://url/of/original/repo
git fetch upstream
git checkout localBranch
git reset --hard upstream/master

That will reset the HEAD, index and working tree for localBranch, making it identical to upstream/master.

You might have to force push that branch (git push -f), but that is not an issue since it is your fork.


I meant after I make some local changes I want to restore the original version of that file that is the same as the one on the master fork repo. So it's like undoing my local changes.

The remote forked repo is referenced by your local repo as 'origin'.

That means a simple git checkout origin/master -- myFile is enough to reset the file to the content from that fork.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thanks, the only branch I have is called master, does that make sense? I get this carya@pecan64:~/edf/ED/build/bin$ git checkout master Already on 'master' carya@pecan64:~/edf/ED/build/bin$ git reset --hard upstream/master HEAD is now at 7b0eec2 Merge pull request #81 from test/master – Herman Toothrot Jun 30 '15 at 22:05
  • @user4050 look good. Your master branch is now the same as the original repo master branch and includes the PR. Perfect. – VonC Jul 01 '15 at 05:40
  • sorry but this is not working. I have cloned master, then I have opened one file and made some changes. Then I tried clone, fetch, pull but when I reopen the file is still not updated. – Herman Toothrot Aug 07 '15 at 10:54
  • @user4050 Opening a file and making some changes is a local operation on your local clone. Unless you push that change, make a PR and wait for that PR to be accepted, any new clone/fetch/pull would not include those "some changes". – VonC Aug 07 '15 at 11:00
  • Sorry for the confusion I meant after I make some local changes I want to restore the original version of that file that is the same as the one on the master fork repo. So it's like undoing my local changes. – Herman Toothrot Sep 02 '15 at 10:47
  • @user4050 I have edited my answer to address your last comment. – VonC Sep 02 '15 at 13:07