How to keep a github fork updated
22 October 2020
Recently, I forked several projects and make some contribution to them by create pull request. But later, I find out that my forked repo is fall behind the original repo after several days.
So I need to keep up to date with the original repo.
1 git command line
Add remote repository:
git clone https://github.com/kimim/djl
cd djl
git remote add awslabs https://github.com/awslabs/djl
List remote repositories:
git remote
awslabs origin
Update all the remotes:
git fetch --all
Fetching origin Fetching awslabs From https://github.com/awslabs/djl * [new branch] mac -> awslabs/mac * [new branch] master -> awslabs/master * [new branch] model-upload -> awslabs/model-upload
Rebase and push
git rebase awslabs/master git push
Now the forked repo is up-to-date.
If you get the error:
hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
You can fix this issue as below:
git push --force-with-lease origin master
2 Magit
Key | command | Input |
---|---|---|
C-x m g | magit-status | |
M a | magit-remote-add | remote name and url |
f a | magit-fetch | |
r u | magit-rebase | rebase upstream |
P p | magit-push |
If upstream is not correct, use r C-u u
to set upstream.
If you get above mentioned error, then fix with following command:
Key | command | Input |
---|---|---|
P -f p | magit-push | git push –force-with-lease |
maigt makes life simple ^_^