Date: May 1, 2024
Topic: Branches in a Nutshell
Recall
What exactly is a git commit?
Latest commits point to previous commits.
What exactly is a git branch?
What is the HEAD pointer?
Notes
- Git commit saves a commit object that points to the current state of your repo aka snapshot.

Commit and Tree
- The next commit will have a pointer to this commit.

- Git branch is a lightweight movable pointer to one of the commits.
- When we create a new branch it creates a pointer to the same commit we are currently working on.
- The current branch that is being worked on is pointed to by HEAD pointer,
git log --decorate can be used to check this.
<aside>
📌 SUMMARY: git commit is a pointer to a snapshot of the directory and git branch is a pointer to one of the commit.
</aside>
Date: May 1, 2024
Topic: Switching Branches
Recall
How to move the HEAD pointer?
Branch commits always create a new commit pointing back to the initial commit.
Notes
git checkout <branch> will move the HEAD pointer to that branch.
- If we make a new commit to that branch the commit will point back to the commit which is pointed to by the master branch.

- Now, if we switch back to master and create commits, we will create a divergent history.

- This also makes merging branches easily because their parent is known.
<aside>
📌 SUMMARY: Git branches can be switched using git checkout and can create a tree based structure of commits when working on a project.
</aside>
Date: May 7, 2024
Topic: Basic Merging
Recall
Keep in mind with which branch the changes will get merged with.
Merge conflicts occurs only on editing same part of the code on the same file.
Notes
- Merge creates a new snapshot using the most recent ancestor of the two branches.
- Checkout the branch you want to merge with and write
git merge branch_name .
$ git checkout master Switched to branch 'master' $ git merge iss53 Merge made by the 'recursive' strategy.
- Merge conflicts occurs when same part of the same file has been modified on two different branches. Something like:
`<<<<<<< HEAD:index.html
<div id="footer">contact : [email protected]</div>
<div id="footer"> please contact us at [email protected]
</div>
iss53:index.html`
- Here master and iss53 branches have different content in index.html.
- We need to choose between either code above or below ========.
- After resolution we need to add the files again to mark the conflict as resolved
git branch --merged gives a list of branch merged and using --no-merged option gives those that are not merged into the current branch that is checked out.
<aside>
📌 SUMMARY: Switch to the branch you would like to merge changes to and in case of merge conflicts, you can either accept/reject either one of the code on the branches.
</aside>
Date: May 7, 2024
Topic: Branch Name