Today's github tip - fixing local master

qznc qznc at web.de
Wed Jun 19 03:19:53 PDT 2013


On Tuesday, 18 June 2013 at 20:47:50 UTC, David wrote:
> 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

My advice would be to use more branches. Never commit to a master 
branch, only merge. Thus all your changes stay available on their 
branch and dealing with repo conflicts on master does not risk to 
discard (or hide wrt reflog) any commits.


More information about the Digitalmars-d mailing list