Git Basics: How to push your commits to remote repository?


As of now, as part of the Git Tutorial Series we learned about the changes, the commit to the staging area and viewing the working tree status. Once we are fine with the local branch changes, we need to push it to remote repository.

 

In this part of the tutorial, we will learn how to push these commits/changes to remote. Lets start discussing about the “git push” command and it’s various parameters.

 

$ git push command (www.kunal-chowdhury.com)

 

I hope you are following my "Git Tutorial Series" and reading all the posts linked to that page. Don't forget to share it to your followers, friends and/or colleagues. They might be interested to read those too.

 

Last time (recently) we discussed about "git add", "git commit" and "git status" and today we are going to see and discuss on the topic/command that will help you to push your commits/changes to remote branch of your repository. The command to do this is: git push and it actually updates remote refs along with associated objects.

 

Here is the list of command parameters, which you will find interesting while working with Git repositories and Git branches.

 

Push changes of current branch to remote:

$ git push

$ git push <remote>

$ git push origin

$ git push <remote> <branch>

$ git push origin <branch>

 

Push changes to a specific branch:

$ git push origin <branch>

 

Push the current branch to the same name on remote:

$ git push origin HEAD

 

Push matching branches to origin:

$ git push origin :

 

Push the current branch to the remote ref matching master in the origin:

$ git push origin HEAD:master

 

Push the current branch forcefully to remote:

$ git push origin -f <branch>

$ git push origin --force <branch>

 

Push all branches to remote:

$ git push --all

 

Push a single tag to remote:

$ git push <remote> <tag>

 

Push all the tags to remote:

$ git push origin --tags

 

Push the tags to a remote branch:

$ git push origin --tags <branch>

 

Rename a remote branch by pushing local branch:

$ git push <remote> <localBranch>:<remoteBranch>

 

Remove remote branches that don’t have a local counterpart:

$ git push origin --prune

 

Delete a remote branch:

$ git push <remote> :<branch>                # There's a space between <remote> and ':' (colon)

 

Add tracking refs for every branch that is up to date or pushed:

$ git push -u

$ git push --set-upstream

 

 

Was this post useful? If you came to this page by searching online about “git basics” or “git tutorials”, please have a look into my other blog posts. Subscribe to the RSS feed or the email newsletter to keep yourself updated.

 

 

 


If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

0 comments

 
© 2008-2016 Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top