Git notes:

  • - Pointers for all branches are located in .git/refs/heads
  • Head is reference to the currently checked out branch or commit. Pointer is located in .git/HEAD file
  • Change branch "git checkout <branch>"

$git log
commit 135074045cff79237adf80592223698d9c3c8069 (HEAD -> master)
Author: default user 
Date:   Sun Apr 11 11:21:06 2021 +0200

    3rd commit

commit 04b13cf07ef265ad4354bb09b4c20c9e49b922b0
Author: default user 
Date:   Sun Apr 11 11:20:04 2021 +0200

    2nd commit

commit 02d43df3a2e1889788d454dcf1f73fc58659982b
Author: default user 
Date:   Sun Apr 11 11:19:29 2021 +0200

    first commit

At first, the head is at the last commit (3rd commit)

$cat .git/HEAD                                        

Now checkout the 2nd commit:

    $git checkout 04V13

Then we check that the head is pointing on the 2nd commit (04b13)

$cat .git/HEAD 


2. Creating branches:

\W $git branch temp
$git branch
* (HEAD detached at 1350740)
$ls .git/refs/heads 
master	temp


check that the head is at the last commit. When the branch is created, it points to the same commit as the master (3rd commit)

$cat .git/refs/heads/temp  


When we checkout a branch, the head point on the branch instead of on the master.

$git checkout temp
Switched to branch 'temp'
$cat .git/HEAD 
ref: refs/heads/temp


Rename the branch temp to new-temp

$git branch -m temp new-temp


Delete the new-temp branch:

 $git branch -d new-temp
Deleted branch new-temp (was 1350740).
$git branch
* master


Create a new branch and checkout it with one command. Create a file4.txt and commit the changes

 $git checkout -b BR-1
Switched to a new branch 'BR-1'
$echo "Hello, git" > file4.txt
$git commit -m "First commit in BR-1"
[BR-1 446e83f] First commit in BR-1
 1 file changed, 1 insertion(+)
 create mode 100644 file4.txt


Get the details of the commit on the branch BR-1. The parent of the commit is the "3rd commit" from where we have created the branch BR-1

$git cat-file -p 446e8
 tree 49c1a15f802ef08d24c5a58b24dd4e22a5f65286
parent 135074045cff79237adf80592223698d9c3c8069
author default user  1618166341 +0200
committer default user  1618166341 +0200

Merging branches:

List of files with number 0 if no conflicts and same file with num 1 2 3 displayed three times. The file in master after the merge is the combination of these 3 files

    git ls-files -s

Add a comment