On Windows, set VS Code as your default editor
git config --global core.editor "code --new-window --wait"
Settings are stored in ~/.gitconfig Direct editing :
git config --global --edit
My config https://gist.github.com/NicHub/df87a397567afa9d9107
git help <verb>
git <verb> --help
man git-<verb>
git help config
Create .gitignore file
# exclude everything
/*
# except README.TXT
!README.TXT
git init
git add *.c
git add README.TXT
git commit -m 'initial project version'
git status
git add README.TXT
git add README.TXT
git commit -m "comment"
git commit -a -m "comment" # add modified and deleted files
git checkout myfile # Revert one file
git checkout -f # Revert all files + recover deleted files
git reset --hard HEAD
git lg
git checkout master~2 # 2 revisions back
git checkout 1cc8070 # absolute
git checkout master # To come back to latest
git lg
git checkout master~2 test.md # 2 revisions back
git checkout 1cc8070 test.md # absolute
git checkout master test.md # To come back to latest
git checkout master
git checkout NewBranch
git diff --name-status master..dev
git reflog
git reset README.TXT
git rm -r --cached DIRECTORY
git commit -m "cleanup"
git diff # CLI
git difftool # Diff tool defined in ~/.gitconfig
git lg
git difftool ba23d5b f8cdaad README.TXT
git difftool branch1 master -- myfile.md
git checkout -b NewBranch
git diff master NewBranch
git difftool master NewBranch
GITFILE=path/file.ext
git lg $GITFILE
git difftool c350f90:$GITFILE 9231779:$GITFILE
git difftool HEAD~1 HEAD $GITFILE
git difftool HEAD~2 HEAD~5 $GITFILE
nano ~/.gitconfig
[alias]
lg = log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s'
git log
git lg # Must be defined as alias in ~/.gitconfig
git lg README.TXT
git mv README.TXT README.BAK
http://www.git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
# Crée une branche
git checkout -b newbranch
git commit -a -m "my comment"
# Merge la branche
git checkout master
git merge newbranch
Create a book on GitBook.com and make some changes Then on the local machine
git clone https://git.gitbook.com/nichub/ajeter.git
cd ajeter
git remote add gitbook https://git.gitbook.com/nichub/ajeter.git
Make some change localy and push them to the server
git commit -a -m "update"
git push -u gitbook master
Or make some change on the server and pull them localy
git pull -u gitbook master
git pull -u origin master
git push -u origin master
git stash
git stash list
Pour revenir à l’état d’origine :
git stash apply --index # Avec index
git stash apply # Sans index
git config --get remote.origin.url
git show HEAD --compact-summary
git show HEAD~1 --compact-summary
git config --global core.excludesfile ~/.gitignore
git config --global core.excludesfile "%USERPROFILE%\.gitignore"
branch1=master
branch2=dev
msg="A lot of new stuff"
git checkout $branch2
git lg -11
git status
ID=$(git log ${branch1}..${branch2} --pretty=format:%h | tail -1)
echo $ID
git reset ${ID}
git add -A
git status
git commit --amend -m "${msg}"
git status
git checkout $branch1
git lg -11
git merge $branch2
git branch --delete $branch2
git checkout -b $branch2
git lg -11
git status
git update-index --assume-unchanged "_config.yml"
git update-index --no-assume-unchanged "_config.yml"
## Clone distant branch
git branch -r
git checkout --track origin/branch_name