- Cheat Sheet and Example is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools








Git - How to use Git.


  • Git is a distributed revision control and source code management (SCM) system.
  • Git is a version control system (VCS) for tracking changes in computer files and coordinating work on those files among multiple people.

Web Sites

Deploy Image with Git

Deploy Image with Git

Git Flow Image

Git Flow Image



Command Explanation Example
git --version Disaplay git version
git config --list
git config -l
git config
Git Configuration Example
~]$ git config --global XXXXX
~]$ git config --global

~]$ git config --global --list   <- check
~]$ git config --list   <- check
~]$ cat ~/.gitconfig
        email = xxxxx@xxxxx.xxxx
        name = XXXXXX

SSH Configutation

Create Key
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user01/.ssh/id_rsa): id_rsa_github
Enter passphrase (empty for no passphrase):  Enter
Enter same passphrase again:   Enter
Your identification has been saved in id_rsa_github
Your public key has been saved in
The key fingerprint is:
SHA256:adTGiVrW8xxxxxxxxxxxxx/g0xxxx user01@host
The key's randomart image is:
+---[RSA 3072]----+
|    .+o.      =+ |
|    .+o .= . . o.|
|    x   =.B   *..|
|     o Box o +.+.|
|      +xx   + +o |
|       o o o ..x |
|      . . o . x  |
|       . o . x + |
|          . =.. .|


StrictHostKeyChecking no

Host github
  IdentityFile ~/.ssh/id_rsa_github
  User git
Register your public key on the GtiHub side.
  1. [Settings]
  2. [SSH and GPG keys]
  3. [New SSH key]
Connection Test
$ ssh -T
Warning: Permanently added ',13.xx.xx.xx' (RSA) to the list of known hosts.
Hi kuritaka! You've successfully authenticated, but GitHub does not provide shell access.

Setting Up a Git Repository

Command Explanation Example
git init Create an empty Git repository or reinitialize an existing one git init
git init --bare project1 ← --bare: Create minimum reposibotry
git init --bare --share project1 ← --share: Permit push with same GID
git clone git clone project1 testclone
git clone
git clone project-name.`date +%Y%m%d`
git clone ssh://
$ git clone
$ ls -l project-name
$ git clone project-name.`date +%Y%m%d`
$ ls -l project-name.20210317

git remote
Command Explanation
git remote
git remote -v
list remote repository
git remote add NAME URL
git remote add origin
Register remote repository with local repository
git remote show NAME
git remote show origin
show remote repository with detail
git remote rename OLDNAME NEWNAME
git remote rm NAME
git remote rm origin
$ git init
$ git add -A
$ git commit -m "message"
$ git remote add origin

$ vi xxxxx

$ git add -A
$ git commit -m "message"
$ git push
$ git remote -v
origin (fetch)
origin (push)
$ git remote show origin
* remote origin
  Fetch URL:
  Push  URL:
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)

Daily Work

Command Explanation Example
git pull Update local repogitory from remote repogitory git pull [remote repository PATH] [branch]
git pull origin master
Pull the contents of the master branch in the remote repository to the current branch in the local repository.
git add Add file contents to the index git add test.txt
git add -p ← all files of changed
git add . ← new add and edit files
git add -u ← delete files, edit files, not new files
git add -A or git add -all ← both . and -u
git rm git rm -f test.txt
git commit Record changes to the repository git commit -m “message”
git commit -a ← only changed files, not new file
git status Show the working tree status
git push git push [remote repository PATH] [branch]
git push
git push origin master
← Push to master branch of remote repository called origin
git diff git diff ← between index and working
git diff --cache ← between HEAD and index
git diff --name-status remotes/origin/master ← between local repository and remote reposigotry
git diff [commit id 1] [commit id 2]
git log Show commit logs git log
git log --until=2017-01-18 / git log --before=2017-10-15
git log --after=2017-01-20 / git log --since=2017-10-15
git log --grep='XXXX'
git log --oneline
git log --graph --decorate --oneline
git checkout Cancel edits (before adding) git checkout .
git checkout -f master
git revert git revert HEAD
git reset
git clean Remove untracked files from the working tree git clean -n ← check only(dispalay a deleting files. not delete)
git clean -df ← directory adn file
git clean -xf
git fetch git fetch origin master


Command Explanation Example
git branch --contains
git branch --contains=HEAD
Check the current branch name
git branch -a Check Remote Branch
git branch NEW Crate Branch
git checkout BRANCHNAME Change Branch
$ git branch -a
* main
$ git diff --name-status remotes/origin/main
$ git diff remotes/origin/main
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..9f546dd
--- /dev/null
@@ -0,0 +1,21 @@
+MIT License
+Copyright (c) 2021 Takaaki Kurihara


Cancel edits (before adding)

git checkout  FILE
git checkout  DIRECTORY
git checkout  .         <- all files

Cancel commit, go back to before commit

git reset --hard HEAD^

Returns version of commit

git reset  --hard  COMMITID

git reset  --hard  456ab6a3a46e8f86df939578c848fb9d365xxxx

Check the commit id with the git log command

git checkout COMMITID FILE


Case sensitive

differentiating between capital and lowercase letters.

$ git config -l --local | grep core.ignorecase
$ git config core.ignorecase false
$ git config -l --local | grep core.ignorecase
How to Change

middleware/version-control/git/index.html.txt · Last modified: 2021/09/07 by admin

Page Tools