Pushing Changes
Send your local commits to a remote repository with git push.
Basic Push
Push Commands
| Command | Description |
|---|---|
git push | Push to tracked remote |
git push origin main | Push to specific remote/branch |
git push -u origin main | Push and set upstream |
git push --all | Push all branches |
git push --tags | Push all tags |
First Push
When pushing a new branch for the first time:
git push -u origin main
# or
git push --set-upstream origin main
The -u flag sets up tracking, so future pushes only need:
git push
Push Existing Branch
git push origin feature-branch
Force Push
Warning: Overwrites remote history!
git push --force
# or safer:
git push --force-with-lease
Use --force-with-lease - it fails if someone else pushed.
Push Tags
# Single tag
git push origin v1.0.0
# All tags
git push --tags
Delete Remote Branch
git push origin --delete feature-branch
Push Workflow
1. git add .
2. git commit -m "message"
3. git push
Common Issues
Rejected Push
! [rejected] main -> main (non-fast-forward)
Solution: Pull first, then push:
git pull --rebase
git push
Exercise: Push to Origin
Push your current branch to the origin remote:

