Two git tricks

Two tricks I needed today and definitely want to save for future reference :)

Trick 1: How to reset a ‘master’ branch to a different branch and push it to the remote repository

Nice instructions can be found here:

Note 1: The above instructions force-push all branches to your specifc version, in step 4 it would be useful to specify that you only want the ‘master’ branch pushed :)

Note 2: You might have to do a ‘git reset –hard origin/master’ afterwards on other working copies that previously checked out the ‘master’ branch to resolve the merge conflict hell that can arise :)

Trick 2: Undo a force-pushed action on the remote repo

And as a result from the first note in the previous point, here’s how to use the reflog to undo a change you already pushed to remote:

Bonus trick: Diff the same file between two different branches

Use git difftool and note the ‘–’ separator which indicates filenames will be specified starting from that point.

git difftool branchname_1 branchname_2 -- Some/Directory/File.txt