A list of all the Git Commands that I find useful
git remote add upstream git://github.com/diaspora/diaspora.git
status
git status
git log --graph the_branch_name
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
Add alias to config
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
To view pretty printed commits with an alias
git lg
git checkout -b new_branch_name
git checkout -b new_branch_name dev_branch
git branch -D the_local_branch
git branch -m new_branch_name
git push -u origin the_local_branch
git checkout --track origin/the_remote_branch
git push origin HEAD:the_local_branch
git fetch --all
git pull --all
View all local branches including hidden branches
git branch -a
git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format='%(refname:short)'
git checkout origin/the_remote_branch
git checkout -b the_remote_branch origin/the_remote_branch
Enter merge commit message to merge changes from updated remote branch into local branch to enable push
press "i"
write your merge message
press "esc"
write ":wq"
then press enter
git diff path/to/file
git diff --name-status branch_one..branch_two
git diff mybranch master -- myfile.css
git difftool path/to/file
git checkout path/to/file/to/revert
git checkout -- .
git reset --hard
git clean -f -n
git clean -f
git clean -f -d
git reset
git commit -am "commit message"
git cherry -v development current_branch
git show --name-only <sha>
git reset --hard HEAD~1
This will revert everything from the HEAD back to the commit hash, meaning it will recreate that commit state in the working tree as if every commit since had been walked back. You can then commit the current tree, and it will create a brand new commit essentially equivalent to the commit you "reverted" to.
git revert --no-commit 0766c053..HEAD
git commit
git log --oneline
git checkout HEAD~1
git reset hard origin/master
git checkout development
git checkout master
git pull
git log
git revert 9121c997065b043228763356865c307115c47538
Type message and then esc, :x
git push
git commit --amend -m "New commit message"
git push --force origin current_branch_name
List previous commits since branching
git cherry -v parent_branch
Enter interactive rebase for commit N (where N is the number of commits back)
git rebase -i HEAD~N
Enable INSERT or Replace mode and type reword as per instructions
reword
Then escape, write and quit
esc
:wq
Edit Commit message then escape, write and quit
esc
:wq
To quit the interactive rebase
esc
git rebase --abort
git pull --rebase origin master
First make a backup
git tag BACKUP
If some goes wrong you can run
git reset --hard BACKUP
Use git relog to find the desired commit
git reflog
Then reset head to desired commit
git reset --hard HEAD@{5}
Or alternatively rebase saves your starting point to ORIG_HEAD so this command will revert to pre-rebase state
git reset --hard ORIG_HEAD
git difftool
Launch 'opendiff' [Y/n]: Y
git checkout local_branch_to_merge_into
git merge local_branch_to_merge
git reset --merge
To find commit to revert to
git log
To revert to previous commit
git reset --hard hash_of_commit_to_revert_to
Dry run
git clean -dn
Perform delete of specfied untracked file or directoty
git clean -df directory/to/be/untracked/
Perform delete of all untracked
git clean -df
Overwrite remote branch with local branch
git push -f origin the_branch_name
git rm --cached path/to/file/to/stop/tracking
git commit -m "Removed file that shouldn't be tracked"
git remote -v