
- Git - Home
- Git - Version Control
- Git - Basic Concepts
- Git - Command Line
- Git - Installation
- Git - First Time Setup
- Git - Basic Commands
- Git - Getting Help
- Git - Tools
- Git - Cheat Sheet
- Git - Terminology
- Git - Life Cycle
- Git - Get a Repository
- Git - Adding New Files
- Git - Recording Changes
- Git - Viewing Commit History
- Git Branching
- Git - Branches in a Nutshell
- Git - Creating a New Branch
- Git - Switching Branches
- Git - Branching and Merging
- Git - Merge Conflicts
- Git - Managing Branches
- Git - Branching Workflows
- Git - Remote Branches
- Git - Tracking Branches
- Git - Rebasing
- Git - Rebase vs. Merge
- Git - Squash Commits
- Git Operations
- Git - Clone Operation
- Git - Tagging Operation
- Git - Aliases Operation
- Git - Commit Operation
- Git - Stash Operation
- Git - Move Operation
- Git - Rename Operation
- Git - Push Operation
- Git - Pull Operation
- Git - Fork Operation
- Git - Patch Operation
- Git - Diff Operation
- Git - Status Operation
- Git - Log Operation
- Git - Head Operation
- Git - Origin Master
- Git Undoing
- Git - Undoing Changes
- Git - Checkout
- Git - Revert
- Git - Reset
- Git - Restore Operation
- Git - Rm
- Git - Switch Operation
- Git - Cherry-pick
- Git - Amend
- Git on the Server
- Git - Local Protocol
- Git - Smart HTTP Protocol
- Git - Dumb HTTP Protocol
- Git - The SSH Protocol
- Git - The Git Protocol
- Git - Getting Git on a Server
- Git - Setting up the Server
- Git - Daemon
- Git - GitWeb
- Git - GitLab
- Git - Third Party Hosted Options
- Distributed Git
- Git - Distributed Workflows
- Git - Contributing to a Project
- Git - Maintaining a Project
- Customizing Git
- Git - Configuration
- Git - Hooks
- Git - Attributes
- Git - Init
- Git - Commit
Git Push
The git push command is used to push the commits from our local branch to the relevant branch on the remote repository.
What it does?
Changes synced locally − Sends the committed changes from your local repository to the remote repository.
Collaboration − When modifications are committed locally, they are ready to be shared with collaborators via git push, which updates the remote branch with our changes.
Remote branches updated − The remote branches are updated with the latest commits with your local branch.
Syntax
git push [<remote>] [<branch>]
<remote> is the name of the remote repository.
<branch> is the name of the local branch.
Options
The git push command has the following options:
--force or -f
Using the command git push -f changes can be pushed to a remote repository forcefully.
This feature overrides limitations that would normally prevent use, such as erasing or overwriting already-committed changes.
It should be used carefully, as it has the ability to change repository history and interfere with collaborative work.
git push --force origin main
--force-with-lease
The command git push --force-with-lease ensures that you only force push if no one else has pushed changes to the branch.
In case someone else has updated the branch, your push gets rejected.
git push --force-with-lease origin main
--all
Use of the command git push --all- synchronizes all local branches with the origin remote repository.
Maintains synchronization between all local branches and the corresponding branches on the remote repository.
It is helpful when we want to simultaneously updating all local branches' modifications to the remote repository.
git push origin --all
--tags
Using the git push --tags command you can transfer tags to a remote Git repository from a local repository.
Ensures that tags that are local, but not yet remote, are synchronized.
Enables all local tags to be published to the remote repository.
git push origin --tags
--follow-tags
Using the git push --follow-tags command, you can push both commits and tags to a remote Git repository from a local repository.
The tags that are reachable from pushed commits are sent to the remote repository.
git push --follow-tags
--set-upstream or -u
Creates a tracking connection between the local branch and its remote repository equivalent.
Makes it possible for Git commands such as git pull to automatically retrieve the appropriate remote branch.
Uses the branch.<name>.merge parameter in git-config to configure the tracking relationship.
git push origin --set-upstream or -u
--dry-run
Using the git push --dry-run command you can verify what will happen after pushing the change.
It simulates the push without actually pushing any change to the remote repository.
git push --dry-run origin
--mirror
Using the git push --mirror command you can push all the refs from the local repository to the remote repository.
It makes an exact copy of a repository.
git push --mirror origin
--atomic
The command git push --atomic ensures that either all the references are pushed or none at all.
It ensures atomicity of the push.
git push --atomic origin main
--no-verify
The command git push --no-verify skips the pre-push hooks.
When you don't want to run any checks or tests in Git hooks, this command can be used.
git push --no-verify origin main
--prune
The command git push --prune removes the remote branches that do not have corresponding local branches.
It is useful in the cleanup process
git push origin --prune
--quiet or -q
The command git push --quiet suppresses the output of the push command.
It is useful when detailed output is not required.
git push origin --quiet
<remote> <branch>:<remote-branch>
Using the command git push <remote> <branch>:<remote-branch> you can push to a different branch on the remote.
git push origin main:production
These above mentioned options, when used with git push, provide greater flexibility, helping in better management of branches, tags, force pushes, safety checks, and more.