Git: Push to Remote Branch

The push command has the form of

git push remote_name source_ref:destination_ref

 Example:

git push origin +branch42:branch42

The plus is optional and allows non-fast-forward updates.

Alternate syntax is

git push -f origin branch42

if you omit the destination, it’s implied that it’s the same name. If tracking is set up to a particular branch on the remote it will go to that one. The -f is –force.

Deleting branches has 2 syntaxes, the old:

git push -f origin :branch42

and

git push --delete origin branch42

The first is read as “push nothing into branch42” which deletes it.

One trick is that if you specify . as the remote name, it implies the current repo as the remote. This can be used for updating a local branch without having to check it out:

git push . origin/master:master

will update master without having to checkout master.