5. Creating New Git Repository - rajendrapenumalli/GitNotes GitHub Wiki

Stepby Step Process

  1. Create a new folder
  2. Initialise git in that repo
  3. Create files in that repo folder
  4. Add created files for tracking
  5. Check git status
  6. Check git log
  7. Commit changes to local repo

git init

Usage: git init [repository name]

Sample:

  • mkdir samplerepo
  • cd samplerepo
  • git init

When happens when git init command excuted in a folder?

raj@:~/Learning/Git/samplerepo$ git init
Initialized empty Git repository in /home/raj/Learning/Git/samplerepo/.git/

raj@:~/Learning/Git/samplerepo$ tree .git/

.git/
├── branches
├── config
├── description
├── HEAD
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── fsmonitor-watchman.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── prepare-commit-msg.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   ├── pre-receive.sample
│   └── update.sample
├── info
│   └── exclude
├── objects
│   ├── info
│   └── pack
└── refs
    ├── heads
    └── tags

9 directories, 15 files

1. Create files in that repo folder

raj@:~/Learning/Git/samplerepo$ echo "This a first file going to add git repo" >>readme.txt

2. List files in that repo folder

raj@:~/Learning/Git/samplerepo$ ll
total 16
drwxr-xr-x 3 raj raj 4096 Feb 10 12:58 ./
drwxr-xr-x 3 raj raj 4096 Feb 10 12:49 ../
drwxr-xr-x 7 raj raj 4096 Feb 10 12:58 .git/
-rw-r--r-- 1 raj raj 40 Feb 10 12:58 readme.txt

3. Add created files to git for tracking/to staging area

raj@:~/Learning/Git/samplerepo$ git add readme.txt 

raj@:~/Learning/Git/samplerepo$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

	new file:   readme.txt


raj@:~/LearningContent/Git/samplerepo$ git log
fatal: your current branch 'master' does not have any commits yet

  1. Run git log command now
raj@:~/Learning/Git/samplerepo$ git log
fatal: your current branch 'master' does not have any commits yet
  1. Check .git folder now
raj@:~/Learnin/Git/samplerepo$ tree .git/
.git/
├── branches
├── config
├── description
├── HEAD
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── fsmonitor-watchman.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── prepare-commit-msg.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   ├── pre-receive.sample
│   └── update.sample
├── index
├── info
│   └── exclude
├── objects
│   ├── 21
│   │   └── 52fd658218e534a0399309ab577fa554980ad0
│   ├── info
│   └── pack
└── refs
    ├── heads
    └── tags
  1. Commit file to local repo
raj@:~/Learning/Git/samplerepo$ git commit -m "first file readme.txt commiting"
[master (root-commit) 5b88687] first file readme.txt commiting
 1 file changed, 1 insertion(+)
 create mode 100644 readme.txt
  1. Check .git folder content
raj@:~/Learning/Git/samplerepo$ tree .git/
.git/
├── branches
├── COMMIT_EDITMSG
├── config
├── description
├── HEAD
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── fsmonitor-watchman.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── prepare-commit-msg.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   ├── pre-receive.sample
│   └── update.sample
├── index
├── info
│   └── exclude
├── logs
│   ├── HEAD
│   └── refs
│       └── heads
│           └── master
├── objects
│   ├── 21
│   │   └── 52fd658218e534a0399309ab577fa554980ad0
│   ├── 5b
│   │   └── 886877b2822679f3b8badffc6bbc36891f6f36
│   ├── c9
│   │   └── 04391a801993b923ea60a6208e20504d0f961d
│   ├── info
│   └── pack
└── refs
    ├── heads
    │   └── master
    └── tags
⚠️ **GitHub.com Fallback** ⚠️