How do I update my local repo without losing my already committed changes?
So I forked and cloned and created a new branch, made few changes and made a git commit.
However the original repo (upstream) had some new changes. I want to get them to my local repo and to be exact to the actual branch without losing my already committed changes. I do have one commit right now.
I looked for about an hour on how to do that, but it seems like a dead end without knowing the actual keywords that would get me a result.
Use git pull --rebase it will apply your commit over the new commit.
You can use this:
$ git checkout master # for your current repo $ git remote add other http://url.git $ git fetch other $ git merge other/master # or whatever branch name is the branch you want.
You don't give informations about how you forked the code, but I think you did it through a hosting service (like GitHub).
Anyway the principle is the same:
- Add the main repository as a remote to be able to push and pull from it
- Fetch the latest modifications
- Rebase the modifications onto your work
How to do it in command line:
$ git remote add main http://url.git $ git fetch main $ git rebase main/master master