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

  1. Push the current branch:
git push origin main
  1. Push and set upstream tracking:
git push -u origin feature-branch
  1. Force push with lease (safer):
git push --force-with-lease
  1. Push all branches:
git push --all origin

Tips

  • Use --force-with-lease instead of --force to avoid overwriting others' work.
  • git push alone 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.