Thread overview | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 18, 2013 Today's github tip - fixing local master | ||||
---|---|---|---|---|
| ||||
I often struggle with understanding how github works. A problem I was having often is that I have 3 repositories to deal with: 1. the main one on github (upstream) 2. my github fork of the main one (origin) 3. my local git repository and (2) and (3) got out of sync with (1), causing all my pull requests to go bonkers. What I needed was a "fix (2) and (3) so their masters are identical to (1)'s master." Various attempts at fixing it all failed in one way or another, often with mysterious messages, and cost me a lot of time. yebblies (Daniel Murphy) provided the solution, which is nicely generic: git checkout master git fetch upstream master git reset --hard FETCH_HEAD git push origin master -f So there it is if anyone else has this problem. |
June 18, 2013 Re: Today's github tip - fixing local master | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Am 18.06.2013 21:41, schrieb Walter Bright:
> I often struggle with understanding how github works. A problem I was having often is that I have 3 repositories to deal with:
>
> 1. the main one on github (upstream)
> 2. my github fork of the main one (origin)
> 3. my local git repository
>
> and (2) and (3) got out of sync with (1), causing all my pull requests
> to go bonkers. What I needed was a "fix (2) and (3) so their masters are
> identical to (1)'s master." Various attempts at fixing it all failed in
> one way or another, often with mysterious messages, and cost me a lot of
> time.
>
> yebblies (Daniel Murphy) provided the solution, which is nicely generic:
>
> git checkout master
> git fetch upstream master
> git reset --hard FETCH_HEAD
> git push origin master -f
>
> So there it is if anyone else has this problem.
This should not be generalized!
this resets everything you have done on master to upstream! Anything is
gone, if you actually end up resetting the wrong branch, take a look
into "git reflog", which allows you to revert the hard-reset
|
June 18, 2013 Re: Today's github tip - fixing local master | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 2013-06-18 21:41, Walter Bright wrote: > git checkout master > git fetch upstream master > git reset --hard FETCH_HEAD > git push origin master -f > > So there it is if anyone else has this problem. I don't know what you are doing with your git repositories but you shouldn't have to do a push force (push -f). That's only needed if you changed the history, which "git reset" will do. Instead just sync all: 1. sync local with origin: git checkout master git pull git push origin master 2. sync upstream with master git checkout master git fetch upstream git merge upstream/master git push upstream master 3. sync upstream with origin git push origin master If you have changed the history in any of the repository the above won't work. I also recommend doing all your work in a special branch (not master) or topic branches. -- /Jacob Carlborg |
June 18, 2013 Re: Today's github tip - fixing local master | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 6/18/2013 1:52 PM, Jacob Carlborg wrote: > On 2013-06-18 21:41, Walter Bright wrote: > >> git checkout master >> git fetch upstream master >> git reset --hard FETCH_HEAD >> git push origin master -f >> >> So there it is if anyone else has this problem. > > I don't know what you are doing with your git repositories but you shouldn't > have to do a push force (push -f). That's only needed if you changed the > history, which "git reset" will do. Instead just sync all: > > 1. sync local with origin: > > git checkout master > git pull > git push origin master That didn't work. > 2. sync upstream with master > > git checkout master > git fetch upstream > git merge upstream/master > git push upstream master I didn't try that one. > 3. sync upstream with origin > > git push origin master That didn't work, either. > If you have changed the history in any of the repository the above won't work. Hence my problems with it. > I also recommend doing all your work in a special branch (not master) or topic > branches. I do do all the work in not-master branches. But I make mistakes, and often forget to change branches first. Most of my problems with git revolve around trying to undo mistakes. |
June 18, 2013 Re: Today's github tip - fixing local master | ||||
---|---|---|---|---|
| ||||
Posted in reply to David | On 6/18/2013 1:47 PM, David wrote: > This should not be generalized! > this resets everything you have done on master to upstream! Which is what I wanted to do. > Anything is > gone, if you actually end up resetting the wrong branch, take a look > into "git reflog", which allows you to revert the hard-reset I didn't know about that one. |
June 18, 2013 Re: Today's github tip - fixing local master | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Tuesday, 18 June 2013 at 20:52:59 UTC, Jacob Carlborg wrote:
> If you have changed the history in any of the repository the above won't work.
This is exactly the point. Walter had pushed commits to WalterBright/dmd at GitHub that didn't make it to D-Programming-Language/dmd.
And, completely unrelated, also managed to configure his local clone such that "git fetch upstream" fetched the branches to "origin/*" instead of "upstream/*", which is why any of the previous attempts to help failed.
David
|
June 18, 2013 Re: Today's github tip - fixing local master | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Nadlinger | On 2013-06-18 23:04, David Nadlinger wrote: > This is exactly the point. Walter had pushed commits to WalterBright/dmd > at GitHub that didn't make it to D-Programming-Language/dmd. Then he should have pushed them to upstream as well. > And, completely unrelated, also managed to configure his local clone > such that "git fetch upstream" fetched the branches to "origin/*" > instead of "upstream/*", which is why any of the previous attempts to > help failed. If he managed to that I can understand he ran into problem. -- /Jacob Carlborg |
June 18, 2013 Re: Today's github tip - fixing local master | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Nadlinger | On 2013-06-18 23:04, David Nadlinger wrote: > This is exactly the point. My point is that he shouldn't have changed the history in the first place. He also shouldn't encourage other people to do that. That's the problem if you just type in some commands and don't know that they actually do. -- /Jacob Carlborg |
June 18, 2013 Re: Today's github tip - fixing local master | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 6/18/2013 2:10 PM, Jacob Carlborg wrote:
> On 2013-06-18 23:04, David Nadlinger wrote:
>
>> This is exactly the point. Walter had pushed commits to WalterBright/dmd
>> at GitHub that didn't make it to D-Programming-Language/dmd.
>
> Then he should have pushed them to upstream as well.
No, the procedure is never push to upstream, do P.R.'s.
|
June 18, 2013 Re: Today's github tip - fixing local master | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Kinda related, I can recommend #d and #git on freenode for git help ;) |
Copyright © 1999-2021 by the D Language Foundation