Useful git tasks with difficult to recall commands
I made this list of git commands I was constantly having to look up. I hope other people find them helpful!
Track a new remote branch
git checkout -t <remote>/<whatever>
Undo a merge attempt with conflicts
git merge --abort
Make an existing branch just like another
Switch to the branch you want to change
git reset --hard <other_branch>
Delete a remote branch
git push --delete <remote> <branch>
Stage a deleted file for commit
git rm <filename>
Check out a new empty branch
Checks out the branch
git checkout —orphan <branchname>
Empties all files from it
git rm -rf .
Check out an individual file from another branch
git checkout <branch_name> — <files>
Stash and apply stashed changes
git stash
git stash apply
Written by Devon Campbell
Related protips
5 Responses

Deleting a remote branch got a bit easier to remember a couple versions ago, with the addition of the "--delete" flag. Instead of remembering to prefix branch names with a colon, you can do:
git push --delete <remote> <branch>

@rlaneve That's much better. Thanks for pointing it out to me. I've updated the tip.

You should update the comment to the tip as well, where you still mention colons.

@txels Good catch. Thank you!

You forgot about git rebase -i
for squashing