SAGARFIVE

1. Introduction

2. Git Basics

3.  Git Terminology

4.  Git Branching

5.  Git - Github

6.  Git Add (Git staging)

7.  Git Commit

8.  Github Advanced

9.  Git Remote

4.4 Git branch File hierarchy

  • Git file hierarchy is a way to understand , how files are handles in git branch creation , checkout
  • From parent branch files and commits are copied to child branch
  • The files created, commits are in child branch are not shown/copies to master branch
  • if we need that changes in master branch we need to follow advanced commands like merge, cherrypick
  • now, will see git basic branch creation flow with 1 master branch and two child branches

(i) Default branch is master on git:

  • After creating and initialising the project
  • If we run git log –oneline, the response retrieves your current branch is master

Observations:

  • In master branch, we did not created any files
  • So there we do not have commits

Creating files in master branch

touch Master-file-1
git add Master-file-1
git commit -m “m1”
touch Master-file-2
git add Master-file-2
git commit -m “m2”

(ii) Creating a First branch (Child branch) :

Taskcommandobservation
Creating branchgit branch feature-1Branch created
Move into that created branchgit checkout feature-1Moved into branch

Observations :

(i) After checkout, Head is points to selected/checkout branch

(ii) Files are copied from which branch you created(here we created from master)

(iii) if we check the log , the commits also copied to newly created branch

(iv) Adding 2 files and committing :

Taskcommandobservation
Adding first filetouch feature-1-file-1File created
Adding to staging areagit add feature-1-file-1Added to staging
Committinggit commit -m “F1”Commit added
Adding Second filetouch feature-1-file-2File created
Adding to staging areagit add feature-1-file-2Added to staging
Committinggit commit -m “F2”Commit added

(iii) Creating a Second branch (Child branch) :

Taskcommandobservation
Creating branchgit branch -b feature-2Branch created
Adding file 1 and committingtouch feature-2-file-1 && git add feature-2-file-1 && git commit -m “F3”
Adding file 2 and committingtouch feature-2-file-2 && git add feature-2-file-2 && git commit -m “F4”

Observations :

(i) After checkout, Head is points to selected/checkout branch

(ii) Files are copied from which branch you created(here we created from feature-1)

(iii) if we check the log , the commits , files from parent branch(feature-1) copied to newly created child branch(feature-2)

(iv) Creating another file in master branch   :

Taskcommandobservation
Checkout to mastergit checkout masterMoved to branch
Add filetouch Master-file-3 && git add Master-file-3 && git commit -m “M3”Created and committed
Logsgit log –onelineCommit history

Observations:

(i) After checkout, Head is points to selected/checkout branch

(ii) Once checkout you can only see two files because in master, we created two only, that files only shows, the child branch files wont shows/added here

(example : child have rights to parents assets (so child branch(feature 1) copies parent branch(master) files and commits

(iii) After adding file, committing

(iv) if we check the log , the commits also copied to newly created branch

Here we can see graphical representation :