Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialhuckleberry
14,636 PointsWhy does github have the -u option in the copy-paste code for your first push?
Both in the video as well as on github, the copy pasta code for
... or push an existing repository from the command line.
is
git remote add origin https://github.com/username/reponame.git
git push -u origin master
Yet Alyson La leaves out the -u and doesn't even mention it.
I'm just wondering... what's the deal with the differences and does it even matter? If the -u is unnecessary, why does github include it in that portion of the process?
Oh, and unimportant sidenote: git bash for windows offers up a dialog box for you to enter both your username and your password into after hitting enter on the whole git push origin master
portion.
It's pretty dang cool and caught me off guard lol.
Anyway, awesome stuff so far.
Cheers,
Huck -
2 Answers
Kevin Korte
28,149 PointsThe -u
flag with git is a very important concept. What it does is it sets your upstream branch, so git knows the next time you do git push
, git pull
, or git fetch
without arguments, it's going to look for whichever branch you set as upstream.
I think by default, git is going to set the upstream to master, but lets say you are working on a new feature, and that feature had it's own branch that wasn't the master, like it should, you could set that branch as your upstream, so git knows when you pass it commands without arguments, you're talking about that upstream branch.
Does that make sense?
Alyson La
Treehouse Guest TeacherNice catch Huck! The reason I left the -u
out is because...it's confusing as a beginner concept. :)
As Kevin mentions, by adding the -u
, one could then hypothetically leave off the arguments - the origin master
part & just do git push
or git pull
etc.
I have found, however, the muscle memory of explicitly typing out the arguments i.e. the name of the remote (in this case origin
) and the name of the branch (in this case master
) to be good practice.
huckleberry
14,636 PointsThanks Alyson. You're spot on ... "confusing beginner concept" and I'm right there with you about the muscle memory thing. Big fan of "learn X the hard way" method and the muscle memory.
Thanks for chiming in.
Cheers,
Huck -
huckleberry
14,636 Pointshuckleberry
14,636 PointsNope, not at all lmao.
Don't know what upstream is. While I took the Git Foundations course ages ago, I foolishly never dug into it and got my feet wet for real like I should have because it was in all honestly still intimidating and confusing and the course just barely touched on actually using github so github itself was just a morass of confusion and frustration.
Thanks for trying though
Cheers,
Huck -
Kevin Korte
28,149 PointsKevin Korte
28,149 PointsNow worries.
Something to not confuse, is git is a version control package, github is a website that remotely hosts git repos. Bitbucket, is another website that will remotely host git repos.
When you have multiple developers on a project, typically that project is going to be hosted on a remote repo, or repository. Each developer has their own local copy of the project on their computer. Basically, the remote repo becomes the master that everybody works off of. Everyone else's local repos that they work from, would be downstream, or below the master. The opposite is true, to push code from your local branch, to the master, and that is moving upstream. The -u flag just tells git exactly which branch on the remote repo you want to set as default.
huckleberry
14,636 Pointshuckleberry
14,636 Pointsohhh ok, well, alright so I knew about the git vs the github thing but I wasn't putting two and two together regarding upstream.
Ok, so... wait. The
git push -u origin master
is saying "push everything here to the master branch" which is sending it 'upstream' to the master branch aka the main repo. And leaving off the -u then defaults to the master branch? However, if you're working on a branch ... let's say the project is a website and there's a branch named user-survey-form. You want to push your work to THAT branch, am I correct in assuming that you would dogit push -u user-survey-form https://github/username/repo.git
?That's.... I ... I should probably just keep watching the videos.
lol
Thanks anyway.
Cheers,
Huck -