git config (~/.gitconfig)
$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]
$ git config --global core.editor emacs
$ git config --global merge.tool vimdiff
~/.gitignore [.a, .o and temporary files from emacs]
$ cat .gitignore
*.[oa]
*~
# a comment - this is ignored
# no .a files
*.a
# but do track lib.a, even though you're ignoring .a files above
!lib.a
# only ignore the root TODO file, not subdir/TODO
/TODO
# ignore all files in the build/ directory
build/
# ignore doc/notes.txt, but not doc/server/arch.txt
doc/*.txt
# ignore all .txt files in the doc/ directory
doc/**/*.txt
$ git config --global alias.co checkout
$ git config --global alias.br branch
$ git config --global alias.ci commit
$ git config --global alias.st status
$ git config --global alias.unstage 'reset HEAD --'
$ git config --global alias.last 'log -1 HEAD'
$ git config --global alias.visual '!gitk'
+ git config --list
$ git init
$ git add *.c
$ git add README
$ git commit -m 'initial project version'
$ git push origin master
+ Edit <file>
+ git add <file>
+ Edit <file> again
+ git status (now shows <file> as both staged and unstaged)
+ git commit <---- Will commit last edit
git diff --cached // git diff --staged
--- {Staged but not committed} Vs {previously committed}
remove accidentally staged file
$ git rm --cached readme.txt
$ git rm log/\*.log
git commit -am <msg>
Show changes from a commit
git show <commit-hash>
$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend
Ammend commit message before push
$ git commit --amend -m "New commit message"
git reset --hard HEAD~1
Commit only current directory
git commit -m "<blah>" -- .
Commit specific directory
git commit -m "<blah>" -- <dir>
Unstage (Undo staged file)
This just unstages the <file>, => won’t erase your changes. -> follow by checkout if changes need to be discarded.
$ git reset HEAD <file>
Discard changes (Undo unstaged changes)
$ git checkout -- <file>
Revert to a specific commit
$ git checkout <SHA1 hash> file/to/restore
Revert to last committed version
$ git checkout HEAD file/to/restore
$ git checkout HEAD~1 file/to/restore
Rewrite history (undo some commit in the past)
+ rebase
+ http://christoph.ruegg.name/blog/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.html
+ git rebase -i dd61ab32^
Reset last commit (committed but not pushed)
+ git reset --hard HEAD~1
+ git remote
+ git remote -v
$ git remote add pb git://github.com/paulboone/ticgit.git
$ git remote -v
origin git://github.com/schacon/ticgit.git
pb git://github.com/paulboone/ticgit.git
$ git fetch pb
pull == fetch + merge
$ git push [remote] [branch]
$ git push origin master
$ git remote show origin
* remote origin
URL: git://github.com/schacon/ticgit.git
Remote branch merged with 'git pull' while on branch master
master
Tracked remote branches
master
ticgit
$ git remote rm <remote>
$ git remote rename <remote> <renamed-remote>
$ git tag -a v1.4 -m 'my version 1.4'
$ git push origin v1.4
$ git push origin --tags
+ Git Objects
[commit object] -> [tree object] -> \ -> [blob]
\ -> [blob]
\ -> [blob]
+ branch == pointer to commit object.
+ Default branch -> master
+ HEAD -> pointer to current branch.
$ git branch testing
$ git checkout testing
Create and switch to a branch
$ git checkout -b testing
See last commit on each branch
git branch -v
Push local branch to remote
git push -u origin <branch>
$ git checkout master
$ git merge testing
$ git branch -d testing
[c0] <- [c1] <- [c2] <- [c4 | master]
\
<- [c3] <- [c5 | branch2]
===>
[c0] <- [c1] <- [c2] <- [c4] <- <- <- [c6 | master]
\ /
<- [c3] <- [c5 | branch2] <-
Launches vimdiff or a configured merge tool
$ git branch
iss53
* master
testing
show merged and non-merged branches
$ git branch --merged
$ git branch --no-merged
Deleting an ‘unmerged’ branch will fail
$ git branch -D unmerged
[c0] <- [c1] <- [c2] <- [c4 | master]
\
<- [c3] <- [c5 | branch2]
===>
[c0] <- [c1] <- [c2] <- [c4] <- [c3'] <- [c5' | master | branch2]
rebase (replay) from server and client onto branches master branch
$ git rebase --onto master server client
$ git push origin :serverfix
To [email protected] :schacon/simplegit.git
- [deleted] serverfix
$ git push origin --delete <branchName>
Switch to a previous commit (Move HEAD to some previous commit)
+ git checkout <commit-id>
Post checkout to a previous commit, Switch back to latest commit
+ git checkout <branchname>
http://git-scm.com/documentation
https://git.wiki.kernel.org/index.php/GitSubmoduleTutorial
create <new branch> at repo/master or repo/dev
// OR
git checkout -b feature_branch
git push -u origin feature_branch
git fetch origin -- should sync <new branch>
git checkout -b <new branch> origin/<new branch>
add, commit
git branch -vv
git push origin <new branch>:<new branch>
pull request
merge
(remove remote branch after merging)
git branch --merged
(remove locally too)
git branch -d <new branch>
thx .. this is great