What is Git Push?
The git push command is used to upload files from a local repository to a remote repository. It has also the power to overwrite changes.
Why is it used?
Let’s say you developed a feature, and for that, you make changes in the local repository, now you may use the push command for uploading these changes to the remote repository like GitHub, so other team members and coordinators can see it and update their project work. The command is:
git push <remote> <branch>
There is more add up to these, and these are:
- git push <remote> –force: This command forces the push even if it results in a non-fast-forward merge.
- git push <remote> –all: This command pushes all the local branches to the specified remote repo.
A simple way of using the push command should be:
git push -u origin master
Here git push is the command, -u is a flag and used to set origin as the upstream remote in the git config, the origin is the default name of your remote repository you can replace it with whatever name you want, you can use your repo name instead of origin. And the master is the branch name. Now if you execute git push -u origin master you will get an error, ‘origin’ does not appear to be a git repository because we don’t have a remote repository at this point in time. So, let’s create a remote repository on GitHub with the name Crio (crio means newborn). This is an empty repo at now.

To add this repo project to your GitHub account, use the git remote add command on the terminal, in the directory where your repository is currently stored at.
git remote add <remote-name><remote URL>
This command takes two arguments:
- A remote name, let’s say for example, “origin”
- A remote URL, which is your repo address as shown below.

Now you can run the git remote add command and git push command to push your code work to your repository.

We used crio here in place of origin which is the repo name coz we assign an origin to another repo and if you assign an origin to a certain repo, you cannot use it again.

Now,the code is successfully pushed to the repository.


