How to Set Upstream Branch on Git?

Ashik BhuyanAshik Bhuyan
1 min read

What is Git Upstream Branch?

In Git, the upstream branch refers to the branch in a remote repository that your local branch is linked to or tracks. It is the source of updates for your local branch and allows you to synchronize your branch with the latest changes from the remote repository.

How to Set Upstream Branch on Git?

Prerequisites:

  • Git is installed and configured on your local machine.

  • First fork upstream project

  • Go to your personal account and clone the upstream project on your own account

  • The command "git remote -v" is used to view the remote repositories associated with a Git repository. It displays the URLs of the remote repositories along with their corresponding names.

    git remote -v

  • Set upstream

    git remote add upstream https://gitlab.com/express/repo.git

    https://gitlab.com/express/repo.git => upstream clone URL link

  • If you want GitLab and GitHub in one project 👍

    First, create the same repo on GitHub

    git remote add github https://github.com/repo.git

  • Fetch all branches upstream👍

    git fetch upstream

  • Create and Change branch 👍

  • git checkout -b new_branch

  • To push changes use:

  • git push GitHub

  • git push origin

0
Subscribe to my newsletter

Read articles from Ashik Bhuyan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ashik Bhuyan
Ashik Bhuyan

A forward-thinking software engineer. who can work as a web developer in dynamic environments. Strong knowledge of MERN Stack with vast experience in building Web Applications, using React.js, Next.js, and Redux for the client side, Node.js/Express for the server side, and MongoDB, SQL Server for the database.