$ git config --global user.name "John Doe"
$ git config --global user.email "john@example.com"
$ git config --global --list[alias]
logg = log --oneline --graph --decorate
alias = config --get-regexp '^alias\\.'
state = !git fetch origin && git remote show origin && :
sync = !git fetch origin && git remote prune origin && :This creates a new directory with the name of the repository.
$ git clone https://github.com/user/repository.git$ git clone https://github.com/user/repository.git .git reset --hard
git clean -df
git status
# Discard interactively
$ git clean -d -i$ git reset --hard HEAD~1git fetch origin <branch-name>
git checkout <branch-name>
git branch # You are in the middle of development and want to pull from remote?
# Hide your local modifications with "stash"
$ git stash
# OR
$ git stash save --include-untracked "Optional message"
# Now pull the changes from remote.
$ git pull
# Restore your local modifications and continue your works!
$ git stash pop# After you do "git pull", you probably might be in conflict state
# Configure merging tool if you haven't done before.
# Assuming that you have already installed TortoiseSVN
$ git config --global merge.tool tortoisemerge
# Invoke mergetool and it will bring you all the conflicted files
$ git mergetool# Pull the changes from remote release branch into your local feature branch
# Assuming that you are in branch feature/xxxx
$ git pull origin release/xxxx
# Push the merging result to your remote feature branch
$ git push# Create patch from a commit ID
$ git format-patch <COMMIT_ID>
# Apply the patch to current branch. Append signoff by current user info to the commit message.
$ git am --signoff < patch_file.patch# Git log filter by author without merge commits
$ git log --author="Tin Htun" --no-merges
# Display in one line format
$ git log --pretty=tformat:"%H [%an] %s" --author="Tin Htun" --no-merges# filter Git commits by JIRA ticket for example, then get the included file list and remove duplicates
$ git log --name-only --pretty=format: --grep='filter text' --no-merges | sort | uniq
# for multiple JIRA ticket
$ git log --name-only --pretty=format: --grep='Ticket1|Ticket2' --extended-regexp --no-merges | sort | uniq
(OR)
# set the global config and you don't need to use --extended-regexp
$ git config --global grep.extendRegexp true# Revert the changes from commit(s), create new commit with the changes and default commit message
$ git revert --no-edit [commit id(s)]# To squash the last 3 commits into one:
git reset --soft HEAD~3
git commit -m "New message for the combined commit"# pick commit from somewhere and apply on top of current HEAD
git cherry-pick <space separated commit ids>