Last Updated: September 14, 2018
·
1.564K
· raddevon

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

5 Responses
Add your response

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>
over 1 year ago ·

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

over 1 year ago ·

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

over 1 year ago ·

@txels Good catch. Thank you!

over 1 year ago ·

You forgot about git rebase -i for squashing

over 1 year ago ·