1

What exactly is 'origin' when we say

git remote add origin urlOfNewRepository, or git push add origin master?

Is it the name of the remote repository? If it is then what is it when we create a new repository in github?

For example in https://github.com/username/NewRepository what is 'NewRepository'? what is the difference between this and 'origin' ?

JasonMArcher
  • 12,386
  • 20
  • 54
  • 51
user1906399
  • 723
  • 1
  • 10
  • 25

2 Answers2

2

Is it the name of the remote repository?

No, it is an alias for the url of the remote repo you want to push to.
The default name is origin (used when you said git push without any parameters)

If it is then what is it when we create a new repository in github?

No: that url can actually reference a (yet) non-existing repo. It is a local data.

what is 'NewRepository'?

It is the name of a new repo you can create whenever you want on GitHub.
You can reference it locally (with a git remote add) in your repo.
But if you try to push without having created the repo on GitHub, then (and only then) the push will fail.


See also "Why do I need to explicitly push a new branch?": even if you name your remote 'origin', you will still have to type it on the first push:

git push -u origin master.

Only after that first push will you be able to type git push, and git will push the current branch to origin.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • off topic , but can you tell me what is the difference between git push origin master and git push -u origin master? what is that -u ? – user1906399 Jun 15 '14 at 10:26
  • @user that is what I explain in the link: - u links a local branch to a remote tracking branch ( like origin/master), in order to the next push to know where to push. – VonC Jun 15 '14 at 10:32
  • @user1906399 examples of answers about remote tracking branches:http://stackoverflow.com/questions/24216725/deleting-remote-branch-does-not-remove-from-github/24216793#24216793 – VonC Jun 15 '14 at 10:37
1

origin is the name of the remote. You can also call it user1906399 or hd1 or whatever you want. The target of the alias is a remote repository. If you don't have one, it is the reference repository for your code. If you have further questions, do leave a comment.

hd1
  • 30,506
  • 4
  • 69
  • 81