Git push is uploading and updating the local changes from the local branch into the remote branch and that can be done using the refs, but to do that you have to specify the branch name and the remote name.

Before executing the git push command, you have to add the new changes to track in git and then commit it.

Then you have to run the following command to upload this change to the remote branch.

git push [remote] [branch-name]

The git push command has three parts:

  • git push is the main command to upload the changes into the remote server.
  • The [remote] specifying the remote name, the default is “origin”.
  • The [Branch name] to define a new line in the development, the default is “master”.

Git Push Options

As you see in the previous paragraphs, you can run the git push command directly using the branch name and the remote name. So in the below example, I will use only the default branch name.

git push origin master

Use Git Push to Update Refs

You can also use the update flag with the main command --update. Or you can use –u beside the command.

git push -u [remote] [branch-name]

The following image shows you the result once executed the git push command.

git push -u origin master

Overwrite the Remote Branch Using git Push Force

Another command allows you to update the remote branch and overwrite the changes with forcefully.

Note: don’t use this command until you make sure you already know what are you doing to don’t lose your commits on the online branch.

Anyway, to use force with git push, you have to use the following command.

git push --force [remote] [branch] 

Wrapping Up

In this article, you learned how to push the local refs into the remote refs using git push command. And also understood what does mean –u flag.

Thank you for reading. Stay tuned for my next articles.