Reputation: 29326
I'm having trouble differentiating between the two git statements, how exactly does one differ? Or do they differ at all?
Upvotes: 1
Views: 155
Reputation: 44649
git push
will git push to the default remote
git push origin
will push to the remote named origin
When you clone a repository, the default remote is origin
and it is automatically as the default upstream. That's why you may not see the difference.
Although, if you init a repo locally, origin
won't be automatically created, e.g.:
git init
git remote add origin ssh://url/to/origin
git push -u origin --all # note there is also other way to set up the upstream
Note that the default remote could be named anything. origin
is only a convention.
Upvotes: 2
Reputation: 10053
**git push**
will directly push the commited changes to the branch on which you are currently present.
git push origin branchname
is used to specifically mention where should the code be pushed. It's always a better option to use this in all cases.
The keyword origin only references to the name used and can be changed in .git/config file in the project folder where git is initialized.
In case of adding a local project to remote. you can either use
git remote add ec2 ssh://username@path_to_project../home/ubuntu/ProjectDir.git
or
git remote add origin ssh://ubuntu@path_to_project../home/ubuntu/ProjectDir.git
The corresponding changes will be reflected in ProjectDir/.git/config file.
Upvotes: 0
Reputation: 1496
It depends on whether you have multiple remote places to push to. git push
without any arguments to the push action, uses the default remote of the active branch. (https://www.kernel.org/pub/software/scm/git/docs/git-push.html and search for "origin").
Your current branch can be set up to track a remote repo (in which case git push
, without origin, would push to that repo), but if there's nothing specified it tries for origin
.
(This is why when using heroku, you generally have to git push heroku
, instead of just git push
.)
Upvotes: 0