Search code examples
gitgithubbitbucketgit-push

What's the difference in these Git commands


I've been using "git push origin fix/my-fix" when i need to push my local branch to the remote one in Bitbucket. now i'm moving to Github and the doc says i need to use "git push -u origin fix/my-fix". i've read the doc and it's not clear yet. can anybody here help the difference? and i'm wondering if there's any difference in git commands in Github and Bitbucket. thanks in advance.


Solution

  • git has a concept of "remotes" - these are like easy nicknames for a repository, so you don't have to use its full URL every time you want to refer to another repository.

    origin is just a remote like any other, but you see it very frequently since when you clone a repository for the first time, git clone will by default set up a remote called origin to refer to the URL that you cloned from.

    The origin is where you got the code from origin-ally.

    -u means

    "Upstream" would refer to the main repo that other people will be pulling from, e.g. your GitHub repo. The -u option automatically sets that upstream for you, linking your repo to a central one. That way, in the future, Git "knows" where you want to push to and where you want to pull from, so you can use git pull or git push without arguments. A little bit down, this article explains and demonstrates this concept.