Git push: send your commits to the remote
git push sends your local commits to the remote repository to share them with your team. Learn how to use it, configure tracking, and handle rejections.
What is git push?
git push sends your local commits to a remote repository (typically on GitHub or GitLab). This is how you share your work with others.
Push only works if your local branch is up to date with the remote. If someone has pushed commits in the meantime, you will need to git pull first.
Git push syntax
git pushPush to the tracked branch
git push -u origin <branch>Push and set up tracking
git push origin --delete <branch>Delete a remote branch
Git push in practice
Simple push, new branch, and handling rejections.
Simple push
New branch
Push rejected
git push --force: use with care
Force push overwrites the remote history. It can delete your colleagues' work.
When it's OK
- On a personal branch after a rebase
- To fix a commit pushed by mistake (alone on the branch)
When it's dangerous
- On main or a shared branch
- When others have already pulled the branch
Part of the Git Remote & Collaboration guide
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
Questions about git push
Practice push and pull in GitQuest
GitQuest investigations simulate team collaboration with remote repositories.
Start the investigations