There are three main sections of a Git project: the Git directory, the working tree, and the staging area.
The Git directory is where Git stores the metadata and object database for your project. it is what is copied when you clone a repository.
The working tree is a single checkout of one version of the project. These files are pulled out of the compressed database in the Git directory and placed on disk for you to use or modify. It is your scratch space, used to easily modify file content.
The staging area is a file, generally contained in your Git directory, that stores information about what will go into your next commit. Its technical name in Git parlance is the “index”, but the phrase “staging area” works just as well.
The Three States in Git : modified(deleted), staged and committed.
The HEAD in Git is the pointer to the current branch reference, which is in turn a pointer to the last commit you made or the last commit that was checked out into your working directory. That also means it will be the parent of the next commit you do. It’s generally simplest to think of it as HEAD is the snapshot of your last commit.
The Index is your proposed next commit. Git populates it with a list of all the file contents that were last checked out into your working directory and what they looked like when they were originally checked out. It’s not technically a tree structure, it’s a flattened manifest, but for our purposes it’s close enough. When you run git commit, that command only looks at your Index by default, not at anything in your working directory. So, it’s simplest to think of it as the Index is the snapshot of your next commit.

Scenario: you pushed a commit to remote repository (eg: github) with your credential
but you see someone else name instead of your name.
reason: Git always takes the name and email in git config –global when pushing a commit , no matter what credential you entered.
$ git config --list user.email=hoangthach2502@gmail.com user.name=Thach Hoang
how to config this:
git config --global user.email "email@example.com" git config --global user.name "Thach HOang"
Scenario: you want to download a repository in local , so that you can work on it.
git clone https://github.com/libgit2/libgit2
Scenario: add one file , modify one file , remove one file, then commit and push to remote repo
$ git status
Changes not staged for commit:
modified: README.md
deleted: oldfile.md
Untracked files:
newfile.txt
$ git add README.md
$ git rm oldfile.md
$ git add newfile.txt
$ git commit -m "First commit"
$ git push origin master (git push )
Scenario: you already have a commit. now you find out that you missed something and need to add it into that commit.
how: update what you want and create new commit with option –amend. it will replace previous commit:
$git commit --amend -m "This is new commit that will replace old one"
Scenario: you modified and messed up a file but not yet in stage. you want to revert it back to original.
git checkout README.txt
Scenario: you already added/removed wrong file into stage. now you want to unstage it , you don’t want that file in the next commit.
git reset HEAD README.txt
Scenario: you already committed the change. now you want to undo the committed and leave file change in the stage(INDEX).
git reset --soft HEAD^ Scenario: Compare modified files (feature-1100)$git diff develop
Create a branch
git checkout -b
Scenario: Update the branch and resolve conflict if any using rebase.
(feature-1100)$git checkout develop (develop)$git pull (develop)$gc feature_1100 (feature-1100)$git rebase develop resolve conflict then continue the rebase process: (feature-1100)$git rebase --continue
Scenario: Squash N last commits into one commit. It make resolving conflict easier.
git rebase --interactive --autosquash HEAD~N
GIT STASH
Scenario: you are working on branch feature-A with changes. Now you need to switch to branch feature-B to do something urgent. git stash help you store the change of feature A and allow you to switch to another branch. you can return to branch feature-A and restore the changes from stash.
Put in stash:
git stash save "Message"
Show stash:
git stash list
Show stash stats:
git stash show stash@{0}
Show stash changes:
git stash show -p stash@{0}
Use custom stash item and drop it:
git stash pop stash@{0}
Use custom stash item and do not drop it:
git stash apply stash@{0}
Delete custom stash item:
git stash drop stash@{0}
Delete complete stash:
git stash clear
…to be update…
Reference links:
http://ndpsoftware.com/git-cheatsheet.html#loc=remote_repo;
https://git-scm.com/book/en/v2/
http://lennonjesus.github.io/git-cheatsheet/