Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a git upstream

Tags:

git

When you have created a github-repo and added the the github-repo as remote

git remote add origin https://github.com/githubname/reponame.git 

then you need to push your first commit with

git push -u origin master 

I read (Why do I need to do `--set-upstream` all the time?) that this a short form for doing

git branch --set-upstream-to my_branch origin/my_branch git push 

What is a upstream exactly and why do I need to set it? There is little information about this on the net. I know that there is a similar topic What does 'git remote add upstream' help achieve?, but in my opinion it does not explain exactly what the upstream is and what git push -u origin master does, especially what is origin master pointing to, is it the local repo or the remote repo?

like image 491
patriques Avatar asked Jun 15 '13 09:06

patriques


People also ask

What does upstream and downstream mean in git?

Generally speaking, upstream is where you cloned from (the origin). Downstream is any project that integrates your work with other works. The terms are not restricted to Git repositories.

What is upstream and origin in GitHub?

upstream generally refers to the original repo that you have forked. (see also "Definition of “ downstream ” and “ upstream ”" for more on upstream term) origin is your fork: your own repo on GitHub, clone of the original repo of GitHub.

What does git push -- Upstream do?

If your push. default is set to simple or upstream , the upstream setting will make git push , used with no additional arguments, just work.

What is upstream and origin?

Steam is a video game digital distribution platform developed by Valve and Origin is a video game digital distribution platform developed by EA. Comparing the two platforms, most gamers prefer Steam to Origin.


2 Answers

In the command

git push -u origin master 

The -u flag means that your local branch will become a tracking branch. That is, a branch that tracks a remote branch (the "upstream" branch), so that future git pull will know which branch to merge from and git push will be directed to the correct remote branch.

origin is the remote repository you are pushing to.

master is the refspec parameter. The refspec parameter specifies which local branch is pushed to what remote branch. It can be complicated, but in this case the short form master means to push the local master branch to the remote branch with the same name, origin/master.

Technically, the tracking adds the following information about the master branch to your .git/config:

[branch "master"]     remote = origin     merge = refs/heads/master 

and it creates a file here .git/refs/remotes/origin/master, representing the remote branch.

like image 69
Klas Mellbourn Avatar answered Oct 09 '22 22:10

Klas Mellbourn


"Upstream" is the repo you cloned (some of) the branches in yours from, and where you push changes to those branches (and optionally entire new branches) once they've been committed. GitHub acts as your upstream because they store the revisions for you, in a centralized location.

like image 20
Ignacio Vazquez-Abrams Avatar answered Oct 09 '22 20:10

Ignacio Vazquez-Abrams