Git Pushing Push a specific object to a remote branch


Example

General syntax

git push <remotename> <object>:<remotebranchname>

Example

git push origin master:wip-yourname

Will push your master branch to the wip-yourname branch of origin (most of the time, the repository you cloned from).


Delete remote branch

Deleting the remote branch is the equivalent of pushing an empty object to it.

git push <remotename> :<remotebranchname>

Example

git push origin :wip-yourname

Will delete the remote branch wip-yourname

Instead of using the colon, you can also use the --delete flag, which is better readable in some cases.

Example

git push origin --delete wip-yourname

Push a single commit

If you have a single commit in your branch that you want to push to a remote without pushing anything else, you can use the following

git push <remotename> <commit SHA>:<remotebranchname>

Example

Assuming a git history like this

eeb32bc Commit 1 - already pushed
347d700 Commit 2 - want to push
e539af8 Commit 3 - only local
5d339db Commit 4 - only local

to push only commit 347d700 to remote master use the following command

git push origin 347d700:master