Skip to main content

Git Push

git push is the git command used to upload the contents of a local repository to the corresponding remote repository. git push updates the remote branch with local commits. It is one of the four commands in Git that prompts interaction with the remote repository. Pushing is capable of overwriting changes; caution should be taken when pushing.

git push is most commonly used to publish an upload local changes to a central repository. After a local repository has been modified a push is executed to share the modifications with remote team members.

Git Push Syntax:

git push <option> [<Remote URL><branch name><refspec>...]

Git Push Common Usage


  • git push <remote> <branch>: Push the specified branch, along with all of the necessary commits and internal objects. This creates a local branch in the destination repository. To prevent you from overwriting commits, Git won’t let you push when it results in a non-fast-forward merge in the destination repository.

    Example:

    git push origin master


  • git push <remote> --force : Force a push that would otherwise be blocked, usually because it will delete or overwrite existing commits. Do not use the --force flag unless you’re absolutely sure you know what you’re doing.

    Example:

    git push origin --force


  • git push <remote> --all : Push all of your local branches to the specified remote.

    Example:

    git push origin --all


  • git push <remote> --tags: Push all local tags that aren't yet in the remote repository

    Example:

    git push origin --tags


  • git push <remote> --delete <branch-name> : Delete a specific remote branch

    Example:

    git push origin --delete dev3

    Output:

    To gitopia://gitopia147dgrtq5ywww473uz680fx2ucex9fv3qnw94zm/hello-world
    - [deleted] dev3

You can learn more about the git push command and its options in git-scm's documentation.