Based on refcardz from DZone (https://dzone.com/refcardz/getting-started-git).
echo "# cheat-sheets" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/amioranza/cheat-sheets.git
git push -u origin master
git config --global user.name “amioranza”
git config --global user.email “[email protected]”
git config --global color.ui “auto”
git init
git add .
git commit –m 'The first commit'
git clone <repo url>
- e.g.:
git clone https://github.com/amioranza/cheat-sheets.git
Every Git commit generates a SHA-1 hash, 40 hex-characters. this allows the distributed work without the central server.
When browsing the repository you can use any portion of the generated hash to view the contents of the commit, 4-5 characters is enough on most cases.
Table of TREEISH
TREEISH | Definition |
---|---|
Head | HEAD The current committed version |
HEAD^ | One commit ago |
HEAD^^ | Two commits ago |
HEAD~1 | One commit ago |
HEAD~3 | Three commits ago |
:/”Reformatting all” | Hybrid method of types 1, 2, and 3. |
RELEASE-1.0 | User-defined tag applied to the code when it was certified for release. |
git log HEAD~3..HEAD
git checkout HEAD^^
git merge RELEASE-1.0
git mv originalfile.txt newsubdir/newfilename.txt
git rm fileyouwishtodelete.txt
git status
git diff
git diff 32d4..
git diff --summary 32d4..
git log
git log --since=yesterday
git log --since=2weeks
git blame <filename>
git stash
git stash pop
git reset hard
git checkout -- FileToRestore.go
git add <file name, folder name, or wildcard>
git add submodule1/PrimaryClass.java
git add .
git add *.java
git add -i
git add -p
git commit
git commit -m "The commit message"
git show
git commit --amend
git branch <new branch name> <from branch>
git branch <new branch name>
git checkout <branch name>
git branch -a
git merge <branch one>
git merge <branch one> <branch two>
git rebase <source branch name>
git rebase <source branch name> <destination branch name>
git tag <tag name>
git tag <tag name> <treeish>
git remote -v
git remote add <remote name> <remote address>
git push
git fetch <remote name>
git merge <remote name/remote branch>
git pull
git pull <remote name>
git pull <remote name> <branch name>
git bundle create catchupsusan.bundle HEAD~8..HEAD
git bundle create catchupsusan.bundle --since=10.days master
git ls-remote catchupsusan.bundle
git fetch catchupsusan.bundle