Useful Git Snippets

Useful snippets

rename branch

git branch -m oldname newname

deleting remote branch

git push origin :newfeature

Get all the branches

git branch -a

Push up everything

git push -u origin --all

Switch commit head

first do:

git log --oneline

using the line above you can see the commits.
use the following line to go the second commit

git reset --hard HEAD~2

See tree files

git ls-tree --name-only -r master

changing the remote origin name

git remote set-url origin

Using command alias

If you rather use the command line and the shortcuts, you can add some lines to your config file and enjoy the power of shortcuts.

To edit the config file do:

vi ~/.gitconfig

And then add the following lines:

    s = status
    co = checkout
    b = branch
    cm = commit -m
    a = add --all
    p = push origin
    pu = pull origin
    l  = log --oneline
    aa = !git add --all  && git commit -m "hk" && git push origin master
    pupu =  !git pull origin master  && git push origin master

Common Issues

Using git for the first time might cause some headahces. The issues below are some that usually pop up in every git user's workflow at least once.

git ignore does not ignore

git rm -r --cached .
Followed by:

git add .

git commit -m "fixes untracked files"

Remove files after they are committed

git rm --cached /\*.lof *.lol *.lomycapequ *.aux *.lot *.out *.toc *.bib


git rm -r --cached _/
git add -u
git cm "remove the folder"