Git/GitHub Part 2
Nov 4 · 4 min read
Here is the link to part 1
Git part 2
Creating Branches
Branches allows us to create an isolated environment where we can try out a certain feature we would like to add before merging it to the master branch without effecting the master branch.

Make a new branch
- To create a new branch use git branch (new branch name)

- Use git branch -a to see all the branches

- If you want to be on a certain branch use git checkout (branch name)

- If you want to delete the branch use git branch -d (branch name)

- If the branch is already fully merged but you want to delete it use -d
- If the branch is not fully merged use -D

- If you want to create a new branch and be on the newly created branch at the same time use git branch -b (new branch name)

Merging branches & Dealing with conflicts
Since we created new branches to work on new features to add to the master branch, we now need a way to merge the new features to the master branch.
Say we have two features, feature-a and feature-b that is being worked on by two different people and it’s time to merge the two features into the master branch.

Merging branches
We have to be on the branch that we want to merge into.

- We can use git merge (feature name we want to merge) to merge the feature.
- We are merging feature-a into the master branch.

- This time we are merging feature-b into the master branch.

- Now master branch is updated with both feature-a and feature-b.
Dealing with conflicts
- Say now with the master branch merged with feature-a and feature-b we want add a new feature so we branch out and create a new branch called feature-c.

- In the mean time someone else that is on the master branch decides to not branch out and work on the master branch and add some new css lines.

- While the person that is on the feature-c branch does not know about the change that has occurred in the master branch and they are working on feature-c and have added a new css line in the same css file.

- Now we want to merge the feature-c branch to the master.
- When we merge we will run into a conflict because the person on the master branch and the person on feature-c worked on the same body selector in the css file and when we try to merge, git does not know what it should merge.



- Now to resolve the conflict we go to the file that has the conflict and we can decide what to keep or what to throw away.
- Once the conflict has been resolved we use git add. and git commit to merge the feature.


