← All languages
Git command of the day

push

Update remote refs along with associated objects.

Description

The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repository. It is the counterpart to git fetch, which imports commits into local branches, while pushing exports commits to remote branches.

Pushing has the potential to overwrite changes, so it needs to be used with caution. Git will reject a push if it would result in a non-fast-forward merge at the remote repository, unless the --force flag is used.

The default behavior of git push without arguments depends on the push.default configuration setting. In modern versions of Git, it pushes the current branch to its upstream counterpart. You can set up tracking branches to simplify the push workflow.

Arguments

NameDescriptionOptional
remote The name of the remote to push to. Defaults to origin. Yes
branch The local branch to push to the remote. Yes
--force Force the push even if it results in a non-fast-forward merge. Yes
--set-upstream Set the upstream tracking reference for the pushed branch. Yes
--tags Push all tags to the remote repository. Yes

Example

git push origin main
git push --set-upstream origin new-feature
git push --force origin main
git push --tags

Reference