(Several of these git examples have been extracted from the book 'Pragmatic guide to GIT' of Travis Swicegood )
git config --global user.name "Fernando Guillen"
git config --global user.email "[email protected]"
cd /develop/myrepo
git config user.name "Fernando Guillen"
git config user.email "[email protected]"
git config --global core.editor /usr/bin/vim
cd /develop/myrepo
git init
git touch README.md
git add README.md
git commit -m "first commit"
git clone [email protected]:747678.git myrepo
git clone --depth 50 [email protected]:747678.git my_repo
git status
git status --short # status decorated
git add path/to/file
git add path/to/folder
git add .
git add -A|--all
git add -u|--update
git add -p|--patch [path/to/file] # choose the changes
git add -e [path/to/file] # edit the diff
git commit -m "Message"
git commit -a -m "Message" # adding all changed files
git commit # open editor for Message
git commit --amend
git commit --amend -C HEAD
git stash
git stash apply
git stash pop # apply and remove from the stack
git stash list
git stash save --patch
git stash drop <stash_name> # remove
git stash clear # remove all
git stash <branch_name> [<stash_name>] # create a branch from an stash
echo ".DS_STORE" >> ~/.gitignore
git config --global core.excludesfile ~/.gitignore
git reset HEAD -- path/to/file
git checkout -- path/to/file # posible data lost!!
git mv path/to/file path/to/file2
git rm -- path/to/file
git rm -r -- path/to/folder
git rm -f -- path/to/file
git clean -n # secure remove not stashed files
git branch <branch_name>
git branch <branch_name> 99a0de8 # from an starting point
git branch <branch_name> <other_branch>
git branch --track <branch_name>
git branch --track <branch_name> <repository>/<branch_name>
git branch --no-track <branch_name>
git checkout <branch_name>
git checkout -b <branch_name> # create branch and checkout into it
git checkout --track -b <branch_name> <repository>/<branch_name>
git branch # only locals
git branch -r # only remotes
git branch -a # all
git branch --merged
git branch --no-merged
git branch --contains 99a0de8 # branchs that contain this commit
git branch -d <other_branch>
git branch -D <other_branch>
git push <remote_repo> :<remote_branch> # deleting a remote branch
git show-branch # show the branch history
git cherry-pick 99a0de8
git cherry-pick --edit 99a0de8 # edit the message
git cherry-pick --no-commit 99a0de8
git tag
git tag v1.0
git tag beta1 99a0de8
git push <remote_repo> v1.0
git push --tags <remote_repo>
git fetch --tags <remote_repo>
git tag -d <tag_name> # remove local tag
git push origin :refs/tags/<tag_name> # remove remote tag
git merge <other_branch>
git merge --no-commit <other_branch> # no create a commit
git merge --no-ff <other_branch> # force create a merge commit
git merge --log <other_branch> # one-line log for each merged commit
git merge -m "Message" <other_branch> # message for this merge commit log
git rebase <other_branch>
git rebase 99a0de8
git reset --hard ORIG_HEAD # undo last rebase after it completes
git rebase --continue
git rebase --abort
git rebase -i 99a0de8
git rebase -i <other_branch>
git rebase -i HEAD~5
git rebase -i HEAD^^^^^
git log
git log --oneline
git log -5
git log HEAD^^^^^..HEAD
git log HEAD~5..HEAD
git log -1 -p HEAD # see changes in last commit
git log -- path/to/folder # commits affecting path/to/folder
git log -- path/to/file
git log --patch -- path/to/file # commits affecting path/to/file in diff format
git log --since="1 week"
git log --after="7 days"
git log --before="1 week"
git log --until="7 days"
git log --grep="some [Rr]eg[Ee]x"
git log --grep="some [Rr]eg[Ee]x" --regexp-ignore-case
git log --author="<user_name>"
git log -S"my string" # 'my string' commits matching
git log -S"my string" --patch # 'my string' commits matching in diff format
git log ..67aab84 # commits in 67aab84 that are not in HEAD
git reflog # history log of the branches changes
git log --raw --abbrev=40 --pretty=oneline | grep -B 1 `git hash-object <filename>`
git log branchA ^branchB
git diff
git diff --staged
git diff HEAD
git diff 99a0de8
git diff 99a0de8..67aab84
git diff -- path/to/file
git log <branch1>..<branch2> # commits in <branch2> those are not in <branch1>
git remote add <remote_repo> [email protected]:747678.git
git remote rm <remote_repo>
git fetch <remote_repo>
git fetch <remote_repo> <local_branch>:remotes/<remote_repo>/<remote_branch>
git fetch --all
git pull
git pull <remote_repo> <remote_branch>
git pull <remote_repo> <remote_branch>:<local_branch>
git pull -f
git pull --rebase <remote_repo> <remote_branch> # fetch and rebase
git push
git push <remote_repo> <remote_branch>
git push <remote_repo> <local_branch>:<remote_branch>
git push -f
git diff --stat HEAD~10
git diff --stat HEAD~10 HEAD
git diff --stat 99a0de8 67aab84
git diff --shortstat HEAD~10
git diff --numstat HEAD~10
git diff --stat -p HEAD
git log --stat
git log --shortstat
git commit --amend
git commit --amend -C HEAD
git reset --hard HEAD^
git reset --soft HEAD^ # removing last commit without removing the changes
git revert 99a0de8
git revert --no-commit 99a0de8
git reset --hard HEAD~3 # removing the last 3 commits
git reset --hard origin/master # reseting to the remote state
git rebase -i 99a0de8^ # using editor to remove the line with 99a0de8
git bisect start
git bisect bad
git bisect good 99a0de8
# bisect process
git bisect reset
git bisect start HEAD 99a0de8
git bisect run /path/to/test/script
git bisect reset
git blame path/to/filename
git init --bare path/to/repo.git
git diff --no-prefix > path/to/patch
patch -p0 < path/to/patch
git format-patch -M 99a0de8 # creating one patch file for each commit
git format-patch master --stdout > path/to/patch.patch # creating one full patch file
git apply --stat path/to/patch.patch # check differences before appling
git apply --check path/to/patch.patch # checking problems before appling
git am path/to/patch.patch # apply the patch
git am --signoff path/to/patch.patch # apply the patch and sign off it
git apply path/to/patch.patch # apply the patch but not stage the changes
git update-index --assume-unchanged .rvmrc