Git: Updating a forked repository
Update your local repository to keep it up-to-date.
$ git pull origin main (...) remote: Enumerating objects: 6, done. remote: Counting objects: 100% (6/6), done. remote: Total 10 (delta 6), reused 6 (delta 6), pack-reused 4 Unpacking objects: 100% (10/10), 1.07 KiB | 78.00 KiB/s, done. From https://<your_forked_repo> * branch main -> FETCH_HEAD f187d39..e437f49 main -> origin/main Updating f187d39..e437f49 Fast-forward ./test.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
Show the working tree status.
$ git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean
Add original repository and call it upstream.
$ git remote add upstream https://<original_repo>.git
List the remote connections. Upstream should be seen here.
$ git remote -v origin https://<your_forked_repo>.git (fetch) origin https://<your_forked_repo>.git (push) upstream https://<original_repo>.git (fetch) upstream https://<original_repo>.git (push)
Fetch upstream.
$ git fetch upstream main remote: Enumerating objects: 14, done. remote: Counting objects: 100% (14/14), done. remote: Total 47 (delta 14), reused 14 (delta 14), pack-reused 33 Unpacking objects: 100% (47/47), 8.08 KiB | 243.00 KiB/s, done. From https://<original_repo> * branch main -> FETCH_HEAD * [new branch] main -> upstream/main
Switch to your master branch.
$ git checkout main Already on 'main' Your branch is up to date with 'origin/main'.
Apply upstream changes into your local repository.
$ git rebase upstream/main Successfully rebased and updated refs/heads/main.
See changes.
$ git status On branch main Your branch is ahead of 'origin/main' by 11 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean
Force push the changes into your remote repository.
$ git push -f origin main