How to push changes to a remote repository
· Category: Git
Short answer
Use git push <remote> <branch> to upload your local commits to a remote repository.
Steps
- Push the current branch:
git push origin main
- Push and set upstream tracking:
git push -u origin feature-branch
- Force push with lease (safer):
git push --force-with-lease
- Push all branches:
git push --all origin
Tips
- Use
--force-with-leaseinstead of--forceto avoid overwriting others' work. git pushalone works after setting upstream with-u.- Delete remote branches with
git push origin --delete branch-name.
Common issues
- Rejected push: pull and merge/rebase first before pushing again.
- Authentication errors: verify your credentials or SSH key setup.