Tag Archives: git

Git: Push to Remote Branch

The push command has the form of

git push remote_name source_ref:destination_ref


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


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.

git: revert (reset) a single file

I’ve made the leap from subversion to git.  I really like git, but there are a few things that confused me.  One is how to (in svn terms) revert an uncommitted file back to the latest version of the file under source control.

git checkout filename

This will checkout the file from HEAD of the current branch, overwriting your changed file.  Since this is the same command used to checkout branches, if you have a file with the same name as a branch you have to make a slight change.

git checkout -- filename

You can also pull files from any location in your repository like this.  man git-checkout for all the details.

git checkout [<tree-ish>] -- [<paths>...]

If you need to revert (reset) all your uncommitted work, the command is

git reset --hard