🌱 BasicsCommonly used

How to push changes to a remote repository

Upload your local commits to a remote repository.

Push current branch
git push origin main

Pushes the main branch to the origin remote.

When to use: Standard push to main/master branch.

Push and set upstream
git push -u origin feature-branch

Pushes the branch and sets the upstream so future "git push" works without arguments.

When to use: First push of a new local branch. After this, just use git push.

Force push (use with caution)
git push --force-with-lease origin branch

Overwrites remote history but fails if someone else has pushed. Safer than --force.

Rewrites remote history. Only use on branches you own. Never on main/master.

Push all branches
git push --all origin

Pushes all local branches to the remote.

Push tags
git push origin --tags

Pushes all local tags to the remote.

← Back to Git Reference