3rdstage's Wiki



Term Description Examples Remarks
tree Either a working tree, or a tree object together with the dependent blob and tree objects (i.e. a stored representation of a working tree)
tree object An object containing a list of file names and modes along with refs to the associated blob and/or tree objects
commit-ish A commit object or an object that can be recursively dereferenced to a commit object
pathspec Pattern used to limit paths in Git commands documentation/*.jpg
tree-ish A commit-ish, a tree object or a tag object
ref A name that begins with refs/ (e.g. refs/heads/master) that points to an object name or another ref (the latter is called a symbolic ref)
refspec Used by fetch and push to describe the mapping between remote ref and local ref push refspec
upstream branch The default branch that is merged into the branch in question (or the branch in question is rebased onto)
  • branch.name.remote
  • branch.name.merge
  • upstream branch of br is origin/br′ = br is tracking origin/br′


Type Format Description Examples
sha1 40-byte hexadecimal string The full SHA-1 object name, or a leading substring that is unique within the repository dae86e1950b1277e545cee180551750029cfe735, dae86e
refname A symbolic ref name master, heads/master, refs/heads/master, tags/master
<rev>~[<n>] the commit object that is the &lf;n>th generation ancestor of the named commit object HEAD~, HEAD~4 master~3


category command description remark
Setup git config Get and set repository or global options git config --get core.autocrlf
git config core.autocrlf false
git config --list List all variables set in config file, along with their values.
git help --all Prints all the available commands on the standard output
git help -m command Display manual page for the command in the man format
Creating git clone Clone a repository into a new directory
git init Create an empty Git repository or reinitialize an existing one
Snapshotting git add
git status Show the working tree status
git diff Show changes between commits, commit and working tree, etc
git commit
git reset Reset current HEAD to the specified state
git reset --hard Resets the index and working tree. Any changes to tracked files in the working tree since commit are discarded.
git reset --hard commit Resets the current branch head to commit Undo commits permanently
git restore Restore working tree files
git rm Remove files from the working tree and from the index
git rm -rf --cached Only remove from the index Working tree files, whether modified or not, will be left alone
Branching git branch List, create, or delete branches
git branch --list List branches. -l
git branch --all -vvvv List both remote-tracking branches and local branches. -avvvv
git branch --move oldbranch newbranch Move/rename a branch and the corresponding reflog. -m
git branch --delete [--force] branch Delete a branch. -d, -D
git checkout branch To prepare for working on branch, switch to it by updating the index and the files in the working tree, and by pointing HEAD at the branch
git checkout -b new-branch --track remote/branch Create and check out a new branch tracking the specified remote branch
git push --set-upstream repository src-branch:dst-branch Push src-branch into dst-branch in repository creating a new branch if dst-branch dose not exist yet and then set the src-branch to track the dst-branch
git branch --set-upstream-to=remote/branch′ branch Set up the branch (specified by branch) tracking information so the upstream specified by remote/branch′ is considered it's upstream branch. git branch --set-upstream-to=origin/bar bar
git branch -u origin/bar bar
git branch --set-upstream-to=upstream Set up current branch tracking information so the upstream specified by upstream is considered it's upstream branch. git branch --set-upstream-to=origin/foo
git branch -u origin/foo
git checkout branch [--] pathspec Overwrite the contents of the files that match the pathspec in both the index and the working tree with the contents at the specified branch
git merge [--ff | --no-ff | --ff-only] commit Join two or more development histories together
git log [branch] -n Show commit logs git log master -3
git log [-n] --graph [--all] Draw a text-based graphical representation of the commit history on the left hand side of the output. git log -3 --graph
git tag Create, list, delete or verify a tag object signed with GPG
git tag --list -n2 List tags git tag -l
git tag --annotate tagname -m "..." Make(create) an unsigned, annotated tag object git tag -a
git tag --delete tagname Delete existing tags with the given names. -d
Sharing git fetch Fetch branches and/or tags (collectively, "refs") from one or more other repositories, along with the objects necessary to complete their histories. git remote add staging; git fetch staging
git fetch [remote remote-branch]
git pull [remote remote-branch] Incorporates changes from a remote repository into the current branch current branch only
git push [remote [src-branch[:dst-branch]...]] Push specified branches to the specified remote repository. branch.*.remote, origin
git push --all [remote] Push all branches (i.e. refs under refs/heads/) into default remote, origin, or specified remote
git push --tags [remote] All refs under refs/tags are pushed
git push --follow-tags Push all the refs that would be pushed without this option, and also push annotated tags in refs/tags that are missing from the remote but are pointing at commit-ish that are reachable from the refs being pushed.
git push --set-upstream For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull and other commands.
git remote -v List tracked repositories
git remote add name url Add a remote git remote add upstream https://....git
git remote rename Rename a remote
git remote remove Remove a remote git remote rm
git remote -v show name Gives some information about a remote git remote -v show origin
git ls-remote List references in a remote repository git ls-remote origin
Inspection git show tag Shows the tag message and the referenced objects. git show v1.0
Stashing git stash list List the stash entries that you currently have. stash@{0}, stash@{1}
git stash show stash Show the changes recorded in the stash entry as a diff between the stashed contents and the commit back when the stash entry was first created
git stash push pathspec Save your local modifications to a new stash entry and roll them back to HEAD (in the working tree and in the index)
git stash pop stash Remove a single stashed state from the stash list and apply it on top of the current working tree state
git stash stash Remove a single stash entry from the list of stash entries.
git clear Remove all the stash entries.
Patching git rebase Reapply commits on top of another base tip
git revert Revert some existing commits Requires your working tree to be clean (no modifications from the HEAD commit)
Administration git clean Remove untracked files from the working tree
git archive Create an archive of files from a named tree git archive -o latest.zip HEAD
Plumbing git ls-files Show information about files in the index and the working tree git ls-files | wc -l
git show-ref List references in a local repository
Guides gitignore ($HOME/.config/git/ignore, $GIT_DIR/info/exclude, .gitignore)
Misc git svn Bidirectional operation between a Subversion repository and Git


A name that begins with refs/ (e.g. refs/heads/master) that points to an object name or another ref.

Type Format Example Remarks
Local branches refs/heads/... refs/heads/2.x, refs/heads/3.x
Remote tracking branches refs/remotes/... refs/remotes/origin/master, refs/remotes/upstream/master
Tags refs/tags/... refs/tags/v0.9, refs/tags/v1.5.RELEASE, refs/tags/v2.0.GA

$ git show-ref

           +--- HEAD
           +--- FETCH_HEAD
           +--- ORIG_HEAD
  .git/ ---+--- refs/ ---+--- heads/ ---+--- main
                         |              |
                         |              +--- next
                         +--- tags/ ----+--- v0.9
                         |              |
                         |              +--- v1.0
                         |              |
                         |              +--- v1.1
                         +--- remotes/ ---+--- origin/ --- main
                         |                |
                         |                +--- origin/ --- HEAD
                         |                |
                         |                +--- upstream/ --- main
                         +--- stash/

Reserved Refs

Reserved Full Description
master refs/heads/master local master branch
origin/master refs/remotes/origin/master
v1.0.1 refs/tags/v1.0.1
HEAD currently checkout commit points out the last commit in the current checkout branch.
FETCH_HEAD the result of the last fetch operation
ORIG_HEAD the commit that was checked out before a merge or rebase operation was started
$ cat .git/HEAD
ref: refs/heads/master
$ git checkout test
$ cat .git/HEAD
ref: refs/heads/test
  • Git Head
    • The HEAD points out the last commit in the current checkout branch. It is like a pointer to any reference.
    • $ git show HEAD


Used by fetch and push to describe the mapping between remote ref and local ref.


Variable Data Type Description Default Remarks
push.followTags boolean If set to true enable --follow-tags option by default. false --no-follow-tags


File State-chart

  Untracked           Modified            Staged        Committed
      |                  |                 |               |
      +- add ------------|---------------->|               |
      |                  |                 |               |
      |                  +- add ---------->|               |
      |                  |                 |               |
      |                  |                 +- commit ----->|
      |                  |                 |               |
      |                  |                 |               |
      |                  |<----------------|-------- edit -+
      |                  |                 |               |
      |<-----------------+-----------------+------ remove -|
      |                  |                 |               |

                       * Tracked = Modified | Staged | Committed
  +-----------+            +---------+            +------------+
  | Untracked | ---add---> | Staged  | <---add--- | Modified   |
  |(workspace)|            | (index) |            |(workspace)|
  +-----------+            +---------+            +------------+
                                |                      ^
                                |                      |
                             commit                  edit
                                |                      |
                                |     +-----------+    |
                                +---> | Committed | ---+


Area Role Description Remarks
Workspace Working directory Consists of files that you are currently working on. Local checkout
Index Staging area, Cache Where commits are prepared.
Stash A place to hide modifications while you work on something else
Local Repository
Upstream Repository


$ git commit -a -m "..."

                         << master, HEAD >>
    +----+        +----+        +----+
    | c1 | <----- | c2 | <----- | c3 | 
    +----+        +----+        +----+

$ git branch iss31  # branch to work on issue 31 - new feature

                         << master, HEAD >>
    +----+        +----+        +----+
    | c1 | <----- | c2 | <----- | c3 | 
    +----+        +----+        +----+
                             << iss31 >>

$ git checkout iss31

                             << master >>
    +----+        +----+        +----+
    | c1 | <----- | c2 | <----- | c3 | 
    +----+        +----+        +----+
                          << iss31, HEAD >>

$ # edits or adds some files
$ git commit -a -m ...

                             << master >>
    +----+        +----+        +----+        +----+
    | c1 | <----- | c2 | <----- | c3 | <----- | c4 |
    +----+        +----+        +----+        +----+
                                        << iss31, HEAD >>

$ # a simple bug is found, create anothter branch for hotfix on 'master' 
$ git checkout master
$ git checkout -b hotfix  # same with 'git branch hotfix; git checkout hotfix'
                         << master, HEAD >>
    +----+        +----+        +----+        +----+
    | c1 | <----- | c2 | <----- | c3 | <----- | c4 |
    +----+        +----+        +----+        +----+
                                           << iss31 >>

                          << hotfix, HEAD >> 
                             << master >>
    +----+        +----+        +----+        +----+
    | c1 | <----- | c2 | <----- | c3 | <----- | c4 |
    +----+        +----+        +----+        +----+
                                           << iss31 >>

$ # edits some files to fix the bug
$ git commit -a -m ...

                                           << hotfix, HEAD >>
                              << master >>   +-- | c5 |
                                   |         |   +----+
    +----+        +----+        +----+ <-----+
    | c1 | <----- | c2 | <----- | c3 | 
    +----+        +----+        +----+ <-----+ 
                                             |   +----+ 
                                             +-- | c4 |
                                              << iss31 >>

$ # after successful testing on hotfix, merge 'hotfix' to 'master'. remove 'hotfix' after merge
$ git checkout master
$ git merge hotfix   # 'master' fast-forwarded
$ git branch --delete hotfix   # --delete == -d

                                              << hotfix >>
                                          << master, HEAD >>
                                             +-- | c5 |
                                             |   +----+
    +----+        +----+        +----+ <-----+
    | c1 | <----- | c2 | <----- | c3 | 
    +----+        +----+        +----+ <-----+ 
                                             |   +----+ 
                                             +-- | c4 |
                                              << iss31 >>

                                          << master, HEAD >>
                                             +-- | c5 |
                                             |   +----+
    +----+        +----+        +----+ <-----+
    | c1 | <----- | c2 | <----- | c3 | 
    +----+        +----+        +----+ <-----+ 
                                             |   +----+ 
                                             +-- | c4 |
                                              << iss31 >>

$ # after hotfix, works on 'iss31' branch with other commits
$ git checkout iss31

                                              << master >>
                                             +-- | c5 |
                                             |   +----+
    +----+        +----+        +----+ <-----+
    | c1 | <----- | c2 | <----- | c3 | 
    +----+        +----+        +----+ <-----+ 
                                             |   +----+      +----+      +----+  
                                             +-- | c4 | <--- | c6 | <--- | c7 | 
                                                 +----+      +----+      +----+
                                                                   << iss31, HEAD >>

$ # when 'iss31' implemented successfully
$ git checkout mater
$ git merge iss31   # if no conflict, simple three-way merge with another new commit

                                                                                  << master, HEAD >>
                                                 +----+ <------------------------------- +----+
                                             +-- | c5 |                                  | c8 |
                                             |   +----+                           +----- +----+
    +----+        +----+        +----+ <-----+                                    |        |
    | c1 | <----- | c2 | <----- | c3 |                                            |   << iss31 >>
    +----+        +----+        +----+ <-----+                                    | 
                                             |   +----+      +----+      +----+   |
                                             +-- | c4 | <--- | c6 | <--- | c7 | --+
                                                 +----+      +----+      +----+


      A---B---C topic
D---E---F---G master
(master)$ git merge --no-ff topic
      A---B---C topic
     /         \
D---E---F---G---H master
reset --hard
      A---B---C topic
D---E---F---G---H master
(master)$ git reset --hard HEAD~2
      A---B---C topic
D---E---F master
      A---B---C topic
D---E---F---G master
$ git rebase master topic
              A'--B'--C' topic
D---E---F---G master
      A---B---C topic
D---E---A'---F master
$ git rebase master topic
               B'---C' topic
D---E---A'---F master


Topic Reading Remark
Stashing Git stash (Bitbucket)


Basic Snapshotting

add, status, diff, commit, restore, reset




command Description Remark
restore about restoring files in the working tree from either the index or another commit. does not update your branch
reset updating your branch, moving the tip in order to add or remove commits from the branch. can also be used to restore the index, overlapping with git restore.
revert about making a new commit that reverts the changes made by other commits.

git revert is used to record some new commits to reverse the effect of some earlier commits (often only a faulty one). If you want to throw away all uncommitted changes in your working directory, you should see git-reset, particularly the --hard option. If you want to extract specific files as they were in another commit, you should see git-restore, specifically the --source option. Take care with these alternatives as both will discard uncommitted changes in your working directory.



branch, checkout, switch, merge, log, tag


  • A branch in Git is simply a lightweight movable pointer to one of these commits.
  • Every time you commit, the master branch pointer moves forward automatically.
  • HEAD is a pointer to the local branch you’re currently on.
Term Description Remark
Remote-tracking Branch
Upstream Branch


  • How to Check out a Remote Git Branch [Step-by-Step] (30 March 2021)
    • A Git repository itself may have multiple remotes, but a branch can only reference a single remote.
    • The fetch command will connect to the remote repository and retrieve a list of all available branches.
    • git checkout RemoteBranch
  • git checkout a Remote Branch
    • In order to see this newly published branch, you will have to perform a simple "git fetch" for the remote.
    • $ git checkout --track origin/newsletter




fetch, pull, push, remote






Typical Usage

List all configuration

$ git config --list --show-scope --show-origin

Adding new items, committing and pushing them

$ git status .                    // identifies added, modified or untracked items under current local directory
$ git add .                       // updates index
$ git status .                    // confirms the changes to be committed
$ git commit -m "message ..."     // commits changes into local repository
$ git status .                    // confirms all changes are committed
$ git push                        // pushes changes in local repository onto the remote repository
$ git log --name-only -1         // lists files in the last commit

When the HEAD of 'origin/master' has changed since the last sync, '$ git push' would fail with messages including fast-forwards. Then,

$ git pull --rebase
may need manual merge.
$ git push

Working with remote repositories

$ git remote -v          // lists tracking repositories
$ git remote add upstream https://github.com/jpmorganchase/quorum.git     // add a new remote repository to track
$ git branch -r          // lists branches in tracking repositories

Working with branches or tags

$ git tag -ln                                // lists tags
$ git tag -a v2.0.2 -m "before new branch"   // creates a new annotated tag(v2.0.2)
$ git tag origin v2.0.2                      // push a tag to a remote 
$ git push origin --tags                     // pushes all local tags to remote 'origin'

$ git branch                                 // lists branches
$ git branch -a                              // lists both local and remote-tracking branches
$ git branch -avv                            // lists all branches showing hash and upstream branch if any

$ git branch 1.1                             // creates a new branch(1.1) from the master (branch)
$ git branch 2.0.2-ext v2.0.2                // creates a new branch(2.0.2-ext) from a tag(v2.0.2)
$ git push origin advanced:advanced          // creates remote branch 'origin/advanced' from local branch 'advanced'
$ git push --set-upstream origin advanced    // sets upstream(tracking) reference for current branch to 

$ git checkout release-1.1                   // updates working tree to release-1.1
$ git checkout -b gh-pages origin/gh-pages   // copies remote branch to local repository

Tracking changes

$ git log master -3                          // lists 3 recent commits for master branch
$ git log v2.0.2 -3                          // lists 3 last commits before the tag of 'v2.0.2'
$ git log origin/master -1                   // lists last commit of remote branch 'origin/master'
$ git log upstream/master -1                 // lists last commit of remote branch 'upstream/master'
$ git log --name-only -1                    // lists files in the last commit.


Use-case Solution Remarks
Removing untracked files and directories git clean -dx
Removing uncommitted changes on all the tracked files git reset --hard
Undo commits permanently git reset --hard commit
Removing uncommitted changes on a single or selected tracked files
Removing committed changes git revert

Removing untracked files and directories in the working tree

$ git clean -ndx          // -n: dry run, -d: directory also, -x: skip gitignore
$ git clean -ffdx         // -ff: force including files manged by different Git repository

For more, refer

Undoing tracked files

  • To remove uncommitted changes on tracked files in the working tree, use 'git reset --hard'.
$ git reset --hard          // resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.
  • To unstage a staged file, use 'git reset HEAD <<file>>'.
$ git reset HEAD CONTRIBUTING.md
  • To unmodify a modified file, use 'git checkout -- <<file>>'.
$ git checkout -- CONTRIBUTING.md

Removing committed changes


Creating and pushing tag

$ git tag -a v1.0 -m "Ready to offer externally"
$ git push origin v1.0

Creating local repository using existing artifacts and pushing it to the remote bare repository

$ git init
$ git add .
$ git status .
$ git commit -m "..."
$ git remote add origin https://github.com/.../....git
$ git push --set-upstream origin master
$ git remote -v

Look around local repository

$ git status .              // show the working tree status
$ git branch --all -vvvv    // list both remote-tracking branches and local branches.
$ git tag -ln               // list tags
$ git remote -v             // list tracking repositories
$ git show-ref              // list references in a local repository 
$ git log origin/master -3  // lists 3 recent commits for remote branch 'origin/master'
$ git ls-files               // show information about files in the index and the working tree
$ git config -l              // list all variables set in config file, along with their values.



Markup Extension Library
Markdown .markdown, .md https://github.com/gjtorikian/commonmarker
MediaWiki .mediawiki, .wiki https://github.com/nricciar/wikicloth
Textile .textile https://github.com/jgarber/redcloth
AsciiDoc .asciidoc, .adoc http://asciidoctor.org/
reStructuredText .rst

GitHub Pages



  • Desc : Git hosting and collaboration software that you can install yourself
  • License : GNU Affero General Public License



Tips and Tricks

Typical .gitignore

A typical .gitignore file contains

# references
#   https://git-scm.com/docs/gitignore
#   https://github.com/github/gitignore

# source version control related

# IDEs or tools related

# directories for intermediate or final compiled artifacts

# dependencies

# generated artifacts

# runtime outputs

# backups, caches, or temporary artifacts

# misc

# build outputs of Remix-IDE for smart contracts - https://remix-ide.readthedocs.io/en/latest/contract_metadata.html

# don't ignore OpenZeppelin contracts
# !/node_modules/@openzeppelin
# /node_modules/@openzeppelin/*
# !/node_modules/@openzeppelin/contracts-3
# /node_modules/@openzeppelin/contracts-3/build
# /node_modules/@openzeppelin/contracts-3/package.json
# /node_modules/@openzeppelin/contracts-3/**/artifacts
# !/node_modules/@openzeppelin/contracts-4
# /node_modules/@openzeppelin/contracts-4/build
# /node_modules/@openzeppelin/contracts-4/package.json
# /node_modules/@openzeppelin/contracts-4/**/artifacts

For more, refer

Typical .gitattribute

* -text

*.tag -text
*.MF -text
*.aj -text
*.ftl -text
*.mediawiki -text
*.textile -text
*.q -text
*.g -text
*.tokens -text
*.script -text
*.cfg -text
.classpath -text
.project -text
.jsdtscope -text
*.prefs -text
*.component -text
*.launch -text
.springBeans -text
.euml2 -text
.umlproject -text
.clay -text
.fbprefs -text
.pmd -text
.lint4jprefs -text
.jshintrc -text

*.sol linguist-language=Solidity

# Declare files that will always have CRLF line endings on checkout.
*.sln text eol=crlf

# Denote all files that are truly binary and should not be modified.
*.a binary
*.o binary
*.so binary
*.lib binary
*.com binary
*.exe binary
*.dll binary
*.bin binary
*.zip binary
*.7z binary
*.png binary
*.jpeg binary
*.jpg binary
*.gif binary
*.bmp binary
*.tif binary
*.tiff binary
*.mp3 binary
*.mp4 binary
*.avi binary
*.flv binary
*.ico binary
*.class binary
*.jar binary
*.doc binary
*.docx binary
*.xls binary
*.xlsx binary
*.ppt binary
*.pptx binary
*.pdf binary