📅  最后修改于: 2023-12-03 15:30:55.163000             🧑  作者: Mango
In Git, if you have a forked repository, it's essential to configure an upstream repository so that you can push and pull changes made from the original repository. This guide will walk you through how to configure an upstream repository for branch push and pull.
Before configuring the upstream repository, check the current remote repositories that you have with the following command:
git remote -v
This command will show you the list of remote repositories that have been configured with your local Git repository.
To add an upstream repository, use the following command:
git remote add upstream <URL of original repository>
This command will add an upstream remote repository to your local Git repository.
To verify the upstream repository, use the following command:
git remote -v
This command will show you the new remote repository that has been added to your local Git repository.
To push and pull the branches from the upstream repository, use the following commands:
git fetch upstream
This command will fetch the changes made in the upstream repository.
git checkout master
This command will checkout your local repository's master branch.
git merge upstream/master
This command will merge the changes made in the upstream repository to your local repository's master branch.
git push origin master
This command will push the changes made in the upstream repository to your forked repository.
Configuring an upstream repository is essential when working with Git forks. By following these steps, you'll be able to push and pull branches from the original repository with ease.