DEV Community

shun
shun

Posted on

Git Upstream Commands Guide

Git's upstream refers to a default remote branch for a given branch. Setting an upstream makes it easier to synchronize and compare changes between the branch and its corresponding remote branch.

Setting Up Upstream

git remote add upstream <original-repository-url>
Enter fullscreen mode Exit fullscreen mode

This command configures the original repository as a new remote called "upstream".

Configuring an Upstream for a Branch

To set the upstream for a branch:

git branch --set-upstream-to=<remote>/<branch> <local-branch>
Enter fullscreen mode Exit fullscreen mode

For instance, to set the main branch of the origin remote as the upstream for the local feature branch:

git branch --set-upstream-to=origin/main feature
Enter fullscreen mode Exit fullscreen mode

Checking Upstreams

To view all local branches and their respective upstreams:

git branch -vv
Enter fullscreen mode Exit fullscreen mode

Pushing to Upstream

To push changes from the current branch to its upstream:

git push
Enter fullscreen mode Exit fullscreen mode

Pulling from Upstream

To pull changes from the upstream to the current branch:

git pull
Enter fullscreen mode Exit fullscreen mode

By setting up upstreams, you no longer need to specify the remote name and branch name each time you run git push or git pull. This enhances the efficiency of your workflow.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay