git config --global core.excludesfile '~/.gitignore'
git config --global push.default current
alias git="/usr/local/git/bin/git"
git config --global user.name "Your Name"
git config --global user.email you@example.com
git config --global pull.ff only
Use this.
git branch -a
git branch -r
git branch
git remote prune origin --dry-run
git branch --list <pattern>
Pattern accepts wildcards
git push origin --delete <branch>
git branch -d <branch>
git branch -D
git fetch -p
master
is a local "master" branch, while origin/master
is a local copy of the branch named "master" on the remote named "origin".
git branch -m <old_branch> <new_branch>
git add -u
git reset -- path/to/file
git checkout <file> || <SHA>
On a file level, it removes changes from a working directory (instead of stagging area like git reset
).
On a commit level, it switches between branches or commits.
git reset <file> || <SHA>
On a file level, it removes a file from the stagging area.
On a commit level, it removes commits by moving the tip of a branch to a different commit.
Unlike reverting, reset changes git history.
git reset --soft <SHA>
Soft resetting has no affect on working directory or stagging area, all changes are stagged.
git reset --mixed <SHA>
Mixed resetting is the default option.
It leaves all changes in the working directory, but not in the stagging area.
git reset --hard <SHA>
Changes added in the resetted commit are removed, as well as all uncommited changes.
git reflog
git reset HEAD@{<n>}
git reset HEAD <file>
git checkout <file>
git reset --hard HEAD
git reset
git reset <file>
git revert <SHA>
Unlike reset and checkout, it's not possible to revert files, only commits.
Reverting undoes a commit by creating a new commit. It does not change the commit history.
git commit --amend
With this command it is possible to change a commit message or changes in a commit.
git checkout master
git pull origin master
git checkout -b <branch-squash>;
git merge --squash <branch>
git fetch
Fetching remote changes, but doesn't merge them in local (origin/<master>
is updated, but master
is not).
git merge <branch>
Merging changes (usually after fetching).
Equivalent of git fetch
+ git merge
.
Similar to git fetch -a
.
git stash
git stash apply
Apply changes from the latest stash on stack and keep the stash on stack.
Or find a specific stash:
git stash list
and then apply it:
git stash apply stash@{<n>}
git stash pop
Apply changes from the latest stash and remove latest stash from stack.
(git stash pop
== git stash apply
+ git stash drop
).
git checkout master
git pull
git checkout <branch>
git rebase master
and merge rebased changes on master branch:
git checkout master
git merge - -no - -ff <branch>
git push origin master
git rebase -i HEAD~<n>
git tag <tag_name>
git push origin --tags
git tag
git log
git log --oneline
Log all commits in one line (commit SHA and first line of the commit message).
git reflog
If you have to use this one, something is totally messed up :)
git log --all --format='%cN %cE'
List of committers with their email.
More about formatting here.
git fetch
git checkout <branch-cp>
git pull origin <branch-cp>
git cherry-pick <SHA>
git push origin <branch-cp>
SHA is the commit identifier from merged pull request (from the oldest one to newer).
git reset HEAD~
git add <file>
git commit -m”message here”
Repeat as many times as needed.
git add -p <file>
Allows splitting code into chunks (y,n,s,...); gives a choice of commands:
Stage this hunk [y,n,a,d,/,j,J,g,e,?]? ?
y - stage this hunk
n - do not stage this hunk
a - stage this and all the remaining hunks in the file
d - do not stage this hunk nor any of the remaining hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
fixes user/repo#issueNo