Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'git remote add upstream' help achieve?

Tags:

git

github

rebase

I was reading on: https://wiki.diasporafoundation.org/Git_workflow#Rebase_your_development_branch_on_the_latest_upstream

Here is an extract:

Your Repository Up to Date

In order to get the latest updates from the development trunk do a one-time setup to establish the main GitHub repo as a remote by entering:

$ git remote add upstream git://github.com/diaspora/diaspora.git 

Rebase Your Development Branch on the Latest Upstream

To keep your development branch up to date, rebase your changes on top of the current state of the upstream master. See the What’s git-rebase? section below to learn more about rebasing.

If you’ve set up an upstream branch as detailed above, and a development branch called 100-retweet-bugfix, you’d update upstream, update your local master, and rebase your branch from it like so:

$ git fetch upstream  $ git checkout master  $ git rebase upstream/master  $ git checkout 100-retweet-bugfix 

[make sure all is committed as necessary in branch]

$ git rebase master 

Why is adding a 'remote upstream' needed in this case? Coudn't I have just done:

$ git checkout master  $ git pull origin master  $ git checkout 100-retweet-bugfix 

[make sure all is committed as necessary in branch]

$ git rebase master 
like image 704
ben39 Avatar asked Jan 20 '12 22:01

ben39


People also ask

What does git remote add upstream?

You have access to pull and push from origin, which will be your fork of the main diaspora repo. To pull in changes from this main repo, you add a remote, "upstream" in your local repo, pointing to this original and pull from it. So "origin" is a clone of your fork repo, from which you push and pull.

What does adding git remote do?

The git remote command lets you create, view, and delete connections to other repositories. Remote connections are more like bookmarks rather than direct links into other repositories.

What is upstream branch in git?

What is Git Upstream Branch? When you want to checkout a branch in git from a remote repository such as GitHub or Bitbucket, the “Upstream Branch” is the remote branch hosted on Github or Bitbucket. It's the branch you fetch/pull from whenever you issue a plain git fetch/git pull basically without arguments.


2 Answers

The wiki is talking from a forked repo point of view. You have access to pull and push from origin, which will be your fork of the main diaspora repo. To pull in changes from this main repo, you add a remote, "upstream" in your local repo, pointing to this original and pull from it.

So "origin" is a clone of your fork repo, from which you push and pull. "Upstream" is a name for the main repo, from where you pull and keep a clone of your fork updated, but you don't have push access to it.

like image 112
manojlds Avatar answered Oct 01 '22 00:10

manojlds


This is useful when you have your own origin which is not upstream. In other words, you might have your own origin repo that you do development and local changes in and then occasionally merge upstream changes. The difference between your example and the highlighted text is that your example assumes you're working with a clone of the upstream repo directly. The highlighted text assumes you're working on a clone of your own repo that was, presumably, originally a clone of upstream.

like image 36
smparkes Avatar answered Oct 01 '22 00:10

smparkes