git push

will push your code to your existing upstream. Depending on the push configuration, it will either push code from you current branch (default in Git 2.x) or from all branches (default in Git 1.x).

Specify remote repository

When working with git, it can be handy to have multiple remote repositories. To specify a remote repository to push to, just append its name to the command.

git push origin

Specify Branch

To push to a specific branch, say feature_x:

git push origin feature_x

Set the remote tracking branch

Unless the branch you are working on originally comes from a remote repository, simply using git push won’t work the first time. You must perform the following command to tell git to push the current branch to a specific remote/branch combination

git push --set-upstream origin master

Here, master is the branch name on the remote origin. You can use -u as a shorthand for --set-upstream.


Pushing to a new repository

To push to a repository that you haven’t made yet, or is empty:

  1. Create the repository on GitHub (if applicable)
  2. Copy the url given to you, in the form https://github.com/USERNAME/REPO_NAME.git
  3. Go to your local repository, and execute git remote add origin URL