Dav/Devs Footer Logo Dav/Devs

Git Learning Notes

Git Learning Notes
WebsiteLink/URL
SVN vs Githttps://help.github.com/articles/what-are-the-differences-between-svn-and-git/
Learn Git (Code School)https://www.codeschool.com/courses/try-git
Documenationhttps://git-scm.com/documentation
Git Crash Coursehttp://git.or.cz/course/svn.html

2. Typical Actions

Typical Git Actions

3. Code Snippets

3.1. Git Commands

CommandsEffect
git initInitializes a Git repository.
git statusChecks the status of files within a Git repository.
git add <filename>Adds an unversioned file to the staging area.
git add ‘*.<file-extension>’Adds all files with the specified extension to the staging area.
git reset <filename>Removes a file or files from the staging area.
git log?
git remote add <main foldername> <repository location>Adds all files in the staging area into a folder onto a specified remote server.
git pushPushes all files in the staging area into the repository. Similar to SVN commit.
git push -u origin masterThe push command tells Git where to put our commits when we’re ready, and boy we’re ready. So let’s push our local changes to our origin repo (on GitHub). The name of our remote is origin and the default local branch name is master. The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do. Go ahead and push it!
git pullUpdate local files with those from the repository.
git diffCompare between conflicted files.

4. Git Config Aliases

co = checkout
ci = commit
st = status
br = branch
br-r = "branch -r"
br-d = "branch -d"
br-dd = "branch -D"
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
type = cat-file -t
dump = cat-file -p
branch-name = "!git rev-parse --abbrev-ref HEAD"
publish = "!git push -u origin $(git branch-name)"
unpublish = "!git push origin :$(git branch-name)"
diff-sta = "!git diff --name-status"
diff-stg = "!git diff --name-status --cached"
a-a = "!git add -A"
set-gli	= "!git config --global --list"
set-ge = "!git config --global --edit"
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
l-ol = "!git log --pretty=oneline"
l-ol2 = "!git log --pretty=oneline -2"
l-2 = "!git log -2"
l-s = "!git log --stat"
l-s2 = "!git log --stat -2"
m-t = "!git merge -Xtheirs"
m-o = "!git merge -Xours"
r-h = "!git reset --hard $(git branch-name)"
r-m = "!git reset --mixed $(git branch-name)"
r-s = "!git reset --soft $(git branch-name)"
r-Hh = "!git reset --hard HEAD"
r-Hm = "!git reset --mixed HEAD"
r-Hs = "!git reset --soft HEAD"
ci-m = "!git commit -m"
la = "!git config -l | grep alias | cut -c 7-"
st = stash
st-l = stash list
st-s = stash show
st-a = stash apply
st-d = stash drop
st-c = stash clear

Back to articles