Git push Command
In this page:
What is Git Push?
git push uploads the commits on your current local branch to the matching branch on a remote repository, making your work visible and available to everyone else who has access to that remote.
Example: What is Git Push?
git push origin main
Pushing a Branch to Remote
The first time you push a brand-new local branch, git push -u origin <branch> (or --set-upstream) links it to a remote branch of the same name, so every future push or pull from that branch can be a plain git push with no extra arguments. After the upstream link is set once, later pushes of that same branch only need git push (or git push origin <branch> explicitly), since Git already knows which remote branch to update -- explicitly naming the branch is still useful in scripts or CI where the current branch shouldn't be assumed.
Example: Pushing a Branch to Remote
git push -u origin feature-login
Pushing All Branches
git push --all sends every local branch to the remote in one command, which is convenient when you've been working across several branches locally and need to publish all of them at once.
Example: Pushing All Branches
git push --all
Pushing Tags
Tags aren't included in a normal push by default -- you need git push --tags (or git push origin <tagname> for just one) to explicitly upload them, since tags are treated as separate from regular commit history.
Example: Pushing Tags
git push --tags
git push origin v1.0
Force Pushing Safely
Force pushing (git push -f) overwrites the remote's history with your local version, which can silently destroy commits a teammate already pushed. git push --force-with-lease is the safer alternative: it refuses to overwrite the remote if it has commits you haven't seen yet.
Example: Force Pushing Safely
git push --force-with-lease
Chapter Quiz — Complete all 11 topics to unlock
0/11 topics done
Complete these topics first: