In this example, we shall understand
git push origin command.
git push command updates remote references using local references by sending objects necessary to complete the given references.
In simple words,
git push command updates remote repository with local commits.
origin represents remote name where user wants to push the changes. Let’s understand this command in more detail.
1. Git Push
git push command push commits made on local branch to a remote repository.
The git push command basically takes two arguments:
- A remote name, for example, origin
- A branch name, for example, master
This makes the structure of command as:
git push <REMOTENAME> <BRANCHNAME>
In case command line doesn’t specifies where to push with the REMOTENAME argument,
branch.*.remote configuration for the current branch is referred to determine where to push. If the configuration is missing, it defaults to
2. Git Push Origin in Action
git push origin command in action, we shall start with creating a git repository.
First we shall create a directory for master branch.
And in this repository we shall be initializing our Git repository. This shall be done using
git init command.
Now we shall be create a new file in this directory with some text.
Now that we have created our file, we shall be adding it to the repository and then committing the same using
git add and
git commit command respectively.
Now we shall create a directory where we shall be cloning the Git branch that we created in above steps.
After this we shall use
git clone command to clone the master git repository.
To see the git remote server configured, we can use command
git remote. In this, it shall be origin.
We can also use command
git remote -v to see the URLs that Git has stored for the shortname to be used when reading and writing to that remote.
Now we shall see
git push origin command in action. First we shall make some changes to the file in the cloned directory.
After making changes we shall add and commit file using commands
git add and
git commit respectively.
And the final step, we shall use command
git push origin to send the changes to remote repository.
In this example, we learnt the significance of
git push origin command, what happens if it is not specified and it’s usage.