Gangmax Blog

自由之思想,独立之精神

Sync Git Changes Between Different Repositories

I have a project whose code is both in a personal repo and a team repo. I work on the personal repo and need to sync the changes to the team repo. Here are the instructions how to do it.

Assume the repo info is as below.

1
2
3
4
5
> git remote -v
origin https://github.company.com/team/demo-project.git (fetch)
origin https://github.company.com/team/demo-project.git (push)
upstream https://github.company.com/personal/demo-project.git (fetch)
upstream https://github.company.com/personal/demo-project.git (push)

Note that this is the command output in the team repo local copy directory. For the local personal repo, it’s not aware of the team repo. For the local team repo, you need to run the following command to make it be aware of the personal repo “upstream” first(adding the “upstream” remote url):

1
git remote add upstream https://github.company.com/personal/demo-project.git

For the personal repo, I just work on it and commit the changes as normal. When you want to sync the changes from the personal repo to the team repo, run the following commands in the local team repo directory:

1
2
3
4
# 1. Get the changes to the "master" branch of the local repo.
git pull upstream master
# 2. Push the changes to the remote team repo.
git push origin master

Done.

Comments