To add an upstream Git server as a remote repository, use the following command:
cd /path/to/your/repo
git remote add upstream git@upstream-server.com:your-repo.git
Replace git@upstream-server.com:your-repo.git
with the actual URL of the upstream Git server.
Check that the upstream remote was added successfully:
git remote -v
This should output something like:
origin git@primary-server.com:your-repo.git (fetch)
origin git@primary-server.com:your-repo.git (push)
upstream git@upstream-server.com:your-repo.git (fetch)
upstream git@upstream-server.com:your-repo.git (push)
To ensure your local repository is up to date with upstream changes:
git fetch upstream
To merge upstream changes into your current branch:
git merge upstream/main
If you have push access to the upstream repository, you can push changes:
git push upstream main
However, in most cases, student repositories are forks of an upstream project, and push access may not be available. Instead, students may need to create pull requests to contribute changes.
To remove the upstream remote:
git remote remove upstream
To update the upstream remote URL:
git remote set-url upstream git@new-upstream-server.com:your-repo.git
You have successfully added an upstream Git server to your private repository, enabling synchronization with upstream changes and collaboration on student projects.