- Delete the last commit locally and remotely:
git reset HEAD^
git push origin +HEAD # force push the new HEAD commit
- Delete the last commit only remotely:
git push origin +HEAD^:master
- git log enhancement:
- show the difference between commits :
git log -p
- show the n most recent commits :
git log -n
- word difference (for books or papers) :
git log -U1 --word-diff
- Set the default remote repo:
- Edit .git/config. Build an entry :
[branch "master"]
remote = origin
merge = refs/heads/master
- Fast create and switch to a new branch :
git checkout -b
- To rename a branch both locally and remotely:
- git branch -m old_name new_name
- git push origin --delete old_name or git push origin :old_name
- and just to delete a branch locally : git branch -d branch_name
- To check the information of a tracking branch : git branch -vv
- use the git-shell on the git account of the git server if you want to restrict the verified users from shell onto the server
- Remove files from git:
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA' --prune-empty --tag-name-filter cat -- --all
- Remove dangling objects from git database:
git reflog expire --expire=now --all
git gc --prune=now
- The best command to apply a git patch cleanly
git apply --ignore-space-change --ignore-whitespace
- Ignore file mode changes
git config core.fileMode false