Recently, I had to create few pull requests to other repositories and in order to do that I had to track the code on some repositories for updating my copy and finally publishing my changes to them. In such situation following steps/commands can help:
Add the repository you want to track with the following git command
git remote add <give a name to the repo> <URL to the repo>
git remote add anotherGitRepo git@url
- Fetch the repository
git fetch anotherGitRepo
this will fetch all the remote branches. You can check those branches with following command:
git branch -a
this will list all the branches from origin and your newly added anotherGitRepo.
- Now, you can checkout the branch which you want to track from newly added repo
git checkout -b otherMaster anotherGitRepo/master
Now, you can merge this otherMaster into any of your branches.
- If you have write access to newly added repo i.e. anotherGitRepo, you can pretty much publish your changes to it.
e.g. you can push a branch to it like:
git push anotherGitRepo <some branch>
- And when you are done you can remove the new repository with the following git command
git remote rm anotherGitRepo
Hope, it helps. 🙂