Skip to content

Instantly share code, notes, and snippets.

@dimitardanailov
Last active August 31, 2017 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save dimitardanailov/6e401c1aff0a08f2a77c496ebe07fb3c to your computer and use it in GitHub Desktop.
Save dimitardanailov/6e401c1aff0a08f2a77c496ebe07fb3c to your computer and use it in GitHub Desktop.
Git commands
# How to simplify the graph produced by git log --graph
# https://gist.github.com/datagrok/4221767
The graph (git log --graph [--oneline] [--all])
# How to search a Git repository by commit message?
# http://stackoverflow.com/questions/7124914/how-to-search-a-git-repository-by-commit-message
git log --all --grep='Build 0051'
# How to delete a Git branch both locally and remotely?
# http://stackoverflow.com/questions/2003505/how-to-delete-a-git-branch-both-locally-and-remotely
git branch -d <branch_name>
git push <remote_name> --delete <branch_name>
# Review / edit the last commit
git commit --amend
# Set up git to pull and push all branches
# http://stackoverflow.com/questions/1914579/set-up-git-to-pull-and-push-all-branches
git push --all <remote>
# What's the simplest way to get a list of conflicted files?
# http://stackoverflow.com/questions/3065650/whats-the-simplest-way-to-get-a-list-of-conflicted-files
git diff --name-only --diff-filter=U
# How to undo last commit(s) in Git?
# http://stackoverflow.com/questions/927358/how-to-undo-last-commits-in-git
git reset --hard HEAD~1
# How can I undo git reset --hard HEAD~1?
# http://stackoverflow.com/questions/5473/how-can-i-undo-git-reset-hard-head1
git reset --hard <sha1 of desired commit>
# How can I merge two commits into one?
# http://stackoverflow.com/questions/2563632/how-can-i-merge-two-commits-into-one
git reset --soft "HEAD^"
git commit --amend
# How to checkout master to all submodules (sub repositories) of project ?
# http://stackoverflow.com/questions/1030169/easy-way-pull-latest-of-all-submodules

# For git 1.8.2 or above the option --remote was added to support updating to latest tips of remote branches:
git submodule update --recursive --remote 

# For older, git 1.6.1 or above you can use something similar to (modified to suit):
git submodule foreach git pull origin master
# Is it possible to completely empty a remote Git repository?
# https://stackoverflow.com/questions/4922104/is-it-possible-to-completely-empty-a-remote-git-repository

touch README.md
git init
git  commit -m "I am removing all previous commits"
git push <remote_name> <branch_name> -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment