📜  git configure upstream for branch push and pull - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:30:55.163000             🧑  作者: Mango

Git Configure Upstream for Branch Push and Pull

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.

Step 1: Check the Current Remote Repositories

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.

Step 2: Add the Upstream 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.

Step 3: Verify the Upstream 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.

Step 4: Push and Pull the Branches from Upstream

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.

Conclusion

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.