Home > Blockchain >  Merging changes to my local repo without overwriting my changes
Merging changes to my local repo without overwriting my changes

Time:07-09

I would just like to seek some help. I've been browsing over stackoverflow and google but somehow cannot find an answer for this. I am collaborating with someone and he is the owner of the remote repo in Github. I forked his repo and then cloned it to my local repo. I started doing my own changes on my local repo, but my question is, if he updates a his side of the repo, how do I update my side without my changes being overwritten?

I'm not sure which command I should use to safely do this. Should I just pull his changes and re-paste the changes I've made? Sorry if this is a stupid question, I am new to collaborating in Github. Thanks in advance!

CodePudding user response:

I started doing my own changes on my local repo, but my question is, if he updates a his side of the repo, how do I update my side without my changes being overwritten?

The sequence of commands would be:

git remote add upstream https://github.com/original/repository
                                           ^^^^^^^^^^^^^^^^^^^
                                          replace it with the "someone/repo" name

Then when you want to check if your code works on top of their updated code (assuming said code was pushed on their main branch):

git fetch upstream

# replay your current branch work on top of their branch
git rebase upstream/main
# check everything work
...

# Then update your own fork
git push --force

CodePudding user response:

you can just pull his code before pushing yours. if you had not worked on same files you wouldn't have any problem else you might have conflicts in your code, but git will tell you the place at your code where conflicts are and will ask to you to choice between yours code or other.

  • Related