Three-way Code Management
# Assuming the current directory is <your-repo-name>
git remote add upstream https://github.com/alshedivat/al-folio.git
git fetch upstream
# check all branches
git branch -avv
git checkout main # local main tracking personal repo
git rebase upstream/main # rebase from upstream
git push -f # push to personal repo
Manually Add Upstream Branch
We can also manually do the changes. This is the original .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://github.com/yyy/zzz
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
Making changes like this:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://github.com/xxx/zzz
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "upstream"]
url = https://github.com/yyy/zzz
fetch = +refs/heads/*:refs/remotes/upstream/*
[branch "master"]
remote = origin
merge = refs/heads/master
Sync New Commits from Public Repo
If we haven’t make changes at master, we can do:
git checkout master
git pull upstream master # pull public (upstream) to local branch
git push origin master
If there is conflict with your changes:
git checkout master
git fetch upstream
git merge --no-ff upstream/master
git push origin master
...