Git 2 reference · Remotes
git push Command (Git)
Upload local commits and tags to a remote branch; -u sets the upstream, and --force-with-lease rewrites history safely.
Git 2
Syntax
git push [-u] [REMOTE] [BRANCH] git push --force-with-lease git push --tags
Parameters
| Parameter | Description |
|---|---|
-u origin BRANCH |
Push and set upstream tracking. |
--force-with-lease |
Overwrite only if the remote hasn't moved. |
--tags |
Push tags. |
-d origin BRANCH |
Delete a remote branch. |
Examples
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
git init -q --bare ../origin.git; git remote add origin ../origin.git
git push -q -u origin main
git status -sb | head -1
git ls-remote ../origin.git | cut -c42-
Output
## main...origin/main refs/heads/main
Run this on your computer — see “Get Started” for setup.
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
git init -q --bare ../origin.git; git remote add origin ../origin.git; git push -q -u origin main
git commit -q --amend -m 'Initial commit (reworded)'
git push -q origin main 2>&1 | grep -o 'rejected' | head -1
git push -q --force-with-lease origin main && echo 'rewritten safely'
Output
rejected rewritten safely
Run this on your computer — see “Get Started” for setup.
Related
git fetch and git pull· Download new commits from a remote (fetch), or download and integrate them into your branch (pull).git remote· List, add, rename and remove the remote repositories a local repository talks to.git tag· Mark releases with lightweight or annotated tags, list them, and push them to a remote.- Remotes: clone, fetch, pull and push · tutorial