Use aliases to quickly commit and push

Add these two lines to your ~/.gitconfig. If [alias] doesn’t exist there, add it.

    ac = !git add . && git commit -am
    ap = "!f() { git add -A && git commit -m \"$@\" && git push; }; f"

Now you can do both git ac "message" and git ap "message" to commit and commit and push.

Check in an empty directory

Create a .gitignore with this content:

# Ignore everything in this directory
# Except this file

Add something to your last commit

Use git add just as you would for a normal commit. Then:

git commit --ammend

Edit last commit message

git commit --amend -m "New commit message"

Resolve all merge conflicts by overwriting with all local or remote files (source)

To use local files

grep -lr '<<<<<<<' . | xargs git checkout --ours

To use remote files

grep -lr '<<<<<<<' . | xargs git checkout --theirs

Remove local (untracked) files from a current branch

git clean -f

Directories as well

git clean -fd

.gitignore files as well

git clean -fdx

Show a single file from a specific revision

git show <revision>:<filename>

Remove an already pushed tag in a Github / remote repo

git tag -d yourtag
git push origin :refs/tags/yourtag

Undo the last commit

git reset --hard HEAD^

If you don’t care about the changes, or

git reset --soft HEAD^

If you do.

If you’ve already pushed, try this:

git revert HEAD

Show all files that will get added when doing a git add .

git status -u