Initialisation
$ git initClone without the full history
$ git clone --depth 1Status
$ git statusHelp
$ git help logCommon config variables
$ git config --global user.email "me@mail.com"
$ git config --global user.name "me"
$ git config --global color.ui true
$ git config --global core.fileMode false // File permission change ignored
$ git config --global diff.renames 0
$ git config --global merge.renameLimit 999999
$ git config --global --replace-all core.pager "less -F -X"
$ git config --global --add core.pager "less -F -X"Check changes
$ git config --list --global
$ git config --list --show-origin --show-scopeEdit the configuration
$ git config --edit --global
$ git config --editAdd to staging (green to red)
$ git add <file>
$ git add . //stage not staged files
$ git add --all //stage not staged and deleted files
$ git add * //stage not staged and untracked filesAdd Since Git 2.0
$ git add -u :/ //To stage your whole working tree
$ git add -u . //To stage just the current pathAdd to staging with patern
$ git add modules/\*.jpg
$ git add \*.htmlRemove staging (green to red) is the exact oposit to $ git add *
$ git reset * Diff
$ git diff HEAD
$ git diff --staged
$ git diff --name-only <SHA1> <SHA2>
$ git diff --name-only <branch-A> <branch-B>Commit in staging
$ git commit -a -m "First commit"Check logs
$ git log -n 2
$ git log -2
$ git log -p <file>
$ git log origin/master..HEAD
$ git log origin/master..Count logs
$ git log --oneline | wc -lShow branch graph
$ git log --graph --decorate --pretty=oneline --abbrev-commit master origin/master
$ git log --graph --oneline --decorate=full -20 --date=short --format="%C(yellow)%h%C(reset) %C(magenta)[%ad]%C(reset)%C(auto)%d%C(reset) %s %C(cyan)@%an%C(reset)"$ git rm --cached -r *
$ git rm --cached app/\**/*.xmlRestore from staging statging
$ git checkout master
$ git checkout master <file>
$ git checkout master <file>
$ git checkout .Delete changes of a file
$ git reset HEAD <file>
$ git reset -- <file>Delete all changes and return to the last commit
$ git reset --hardReturn to commit
$ git reset <commit>
$ git reset <commit> --soft (leave changes in staging)
$ git reset <commit> --hard (delete changes from staging)| Feature | Git checkout | Checkout | Reset |
|---|---|---|---|
| Switches | branches | Yes | No |
| Restores | files | Yes | No |
| Checks | out files from the staging area | Yes | No |
| Moves | the HEAD pointer | No | Yes |
| Moves | the staging area | No | Yes |
Undo a commit
$ git revert e2eb29Undo - again - a commit
$ git revert revert e2eb29https://stackoverflow.com/questions/5772192/how-can-i-reconcile-detached-head-with-master-origin
$ git branch temp
$ git checkout temp
$ git diff master temp
$ git branch -f master temp
$ git branch -d temp
$ git push origin master$ git remote add origin http://github.com/try-git/try_git.git
$ git push -u origin master
$ git pull origin master
$ git diff HEAD
$ git add octofamily/octodog.txt
$ git diff --staged
$ git reset octofamily/octodog.txtCheck branch
$ git branchCheck commit before push
$ git log origin/master..HEADCheck commit before push
$ git push -u origin devDownloads the latest from remote without trying to merge or rebase anything.
$ git fetch --all
$ git fetch https://${GITHUB_USER}:${GITHUB_PASSWORD}@github.com/{GITHUB_USER}/{GITHUB_REPO}.git ${GIT_LOCAL_BRANCH}Then the '$git reset' resets the master branch to what you just fetched. The --hard option changes all the files in your working tree to match the files in origin/master
$ git reset --hard origin/master
$ git reset --hard FETCH_HEADPush or Pull commits one by one : Push a commit, reset it & push new head to repo
$ git log
$ git push origin <commit>:master
$ git reset --hard <commit>
$ git push -f origin masterFetch + checkout | merge
$ git fetch <remote> <branch>
$ git log
$ git checkout .$ git archive --format=zip HEAD -o `date +%Y%m%d`_${PWD##*/}.zip
$ zip -r `date +%Y%m%d`_${PWD##*/}.zip /directory$ git remote -v
$ git remote set-url origin git@github.com:ACCOUNT/REPO.git$ git checkout <branch-to-override>
$ git fetch --all
$ git reset --hard <remote>/<branch-to-copy>Sync a file between branch, modified in every branch (e.g. css file) Or make a pull-like for only one file
$ git checkout <remote>/<branch> <file name>
$ git diff --name-only <branch-A> <branch-B>The file will be updated, then merge should be without any conflit
.gitkeep isn’t documented, because it’s not a feature of Git.
Git cannot add a completely empty directory. People who want to track empty directories in Git have created the convention of putting files called .gitkeep in these directories. The file could be called anything; Git assigns no special significance to this name.
There is a competing convention of adding a .gitignore file to the empty directories to get them tracked, but some people see this as confusing since the goal is to keep the empty directories, not ignore them; .gitignore is also used to list files that should be ignored by Git when looking for untracked files.
$ git reset *vs
$ git add *$ git merge -X theirs
or
$ git checkout --theirs PATH/FILEvs
$ git merge -s ours
or
$ git checkout --ours PATH/FILE$ Git merge --firt-parent$ find . -name '*.jpg' | xargs git rmpull --rebase is a Git command that fetches the latest changes from the remote repository and then rebases your local branch on top of the remote branch. This effectively combines your local changes with the remote changes without creating a merge commit.
$ git rebase origin/master
vs
$ git merge origin/maste
vs
$ git pull --rebase origin/masterhttps://git-scm.com/docs/git-count-objects
$ git count-objects https://git-scm.com/docs/git-repack
$ git-repack