Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Git Push



The git push command is used to push the commits from our local branch to the relevant branch on the remote repository.

What it does?

Changes synced locally − Sends the committed changes from your local repository to the remote repository.

Collaboration − When modifications are committed locally, they are ready to be shared with collaborators via git push, which updates the remote branch with our changes.

Remote branches updated − The remote branches are updated with the latest commits with your local branch.

Syntax

git push [<remote>] [<branch>]

<remote> is the name of the remote repository.

<branch> is the name of the local branch.

Options

The git push command has the following options:

--force or -f

  • Using the command git push -f changes can be pushed to a remote repository forcefully.

  • This feature overrides limitations that would normally prevent use, such as erasing or overwriting already-committed changes.

  • It should be used carefully, as it has the ability to change repository history and interfere with collaborative work.

git push --force origin main

--force-with-lease

  • The command git push --force-with-lease ensures that you only force push if no one else has pushed changes to the branch.

  • In case someone else has updated the branch, your push gets rejected.

git push --force-with-lease origin main

--all

  • Use of the command git push --all- synchronizes all local branches with the origin remote repository.

  • Maintains synchronization between all local branches and the corresponding branches on the remote repository.

  • It is helpful when we want to simultaneously updating all local branches' modifications to the remote repository.

git push origin --all

--tags

  • Using the git push --tags command you can transfer tags to a remote Git repository from a local repository.

  • Ensures that tags that are local, but not yet remote, are synchronized.

  • Enables all local tags to be published to the remote repository.

git push origin --tags

--follow-tags

  • Using the git push --follow-tags command, you can push both commits and tags to a remote Git repository from a local repository.

  • The tags that are reachable from pushed commits are sent to the remote repository.

git push --follow-tags

--set-upstream or -u

  • Creates a tracking connection between the local branch and its remote repository equivalent.

  • Makes it possible for Git commands such as git pull to automatically retrieve the appropriate remote branch.

  • Uses the branch.<name>.merge parameter in git-config to configure the tracking relationship.

git push origin --set-upstream or -u

--dry-run

  • Using the git push --dry-run command you can verify what will happen after pushing the change.

  • It simulates the push without actually pushing any change to the remote repository.

git push --dry-run origin

--mirror

  • Using the git push --mirror command you can push all the refs from the local repository to the remote repository.

  • It makes an exact copy of a repository.

git push --mirror origin

--atomic

  • The command git push --atomic ensures that either all the references are pushed or none at all.

  • It ensures atomicity of the push.

git push --atomic origin main

--no-verify

  • The command git push --no-verify skips the pre-push hooks.

  • When you don't want to run any checks or tests in Git hooks, this command can be used.

git push --no-verify origin main

--prune

  • The command git push --prune removes the remote branches that do not have corresponding local branches.

  • It is useful in the cleanup process

git push origin --prune

--quiet or -q

  • The command git push --quiet suppresses the output of the push command.

  • It is useful when detailed output is not required.

git push origin --quiet

<remote> <branch>:<remote-branch>

  • Using the command git push <remote> <branch>:<remote-branch> you can push to a different branch on the remote.

git push origin main:production

These above mentioned options, when used with git push, provide greater flexibility, helping in better management of branches, tags, force pushes, safety checks, and more.

Advertisements