Back

Explore Courses Blog Tutorials Interview Questions
+10 votes
3 views
in DevOps and Agile by (230 points)
edited by
Hey folks, I'm quite new to Git so can you please explain what actually the main difference between these two git push and git push origin?

3 Answers

+21 votes
by (10.5k points)
edited by

GIT Push

  • The remote repository is the origin.
  • We assume that remote repository is already defined.

  • The work is implicitly pushed into the remote repository.

  • It works only when we use a single repository.

GIT Push origin

  • The remote repository is not defined.

  • In this, it has to be specified explicitly to be pushed into the repository.

  • It can be used with single as well as multiple repositories.

+5 votes
by (32.3k points)
edited by

Git push implicitly pushes to your work to a remote repository, with the assumption that it already exists. By default, this remote repository is the origin.

Git push is commonly used for pushing your local changes to your public upstream repository. Now, if we assume that the upstream is a remote named “origin” (the default remote name if your repository is a clone) and the branch to be updated to/from is named “master” (the default branch name), the pushing can be done as:

git push origin master

Git push usage:

git push <remote> <branch>

git push <remote> --force

git push <remote> --all

git push <remote> --tags

For more details check this link.

In the case of git push origin, it explicitly specifies to be pushed into a repository called origin.

Git push origin is usually used only where there are multiple remote repositories and you want to specify which remote repository should be used for the push.

For a git push origin command: git push command updates remote references using local references by sending objects necessary to complete the given references.

Simply, we can say that git push command updates the remote repository with local commits. And origin represents a remote name where the user wants to push the changes. To understand this command in more detail, I would suggest you go through this link.

Here is a video that helps you in understaing git,

+4 votes
by (62.9k points)

git push

Before Git version 1.7.11 (excluding 1.7.11), git push (with no parameters) will push all the local branches to the corresponding (branches with the same name) remote branch.

From git version 1.7.11, git push (with no parameters) pushes currently working native branch to tracking (corresponding) remote branch.

Note that before using git push command, you have to add a remote git repository by using

Following is the syntax:

git remote add <name_of_remote_git_repo> <remote_git_repo_url>.git 

example:

    2.

git remote add origin https://github.com/somename/xyz.git

git push origin

  • git push origin works identically as that of git push (without parameters).

  • Here, we tend to presumptuously say that you simply have named your remote repository as the origin.(Name can be changed)

git push origin branch-name

Push your branch-name branch only to remote repository named as the origin. Here, we explicitly define the name of a single branch to push. This approach is advisable (especially for beginners) if you are having more than one local branches, and you are not COMPLETELY sure what you are doing.

I hope it helps you!

Browse Categories

...