Search⌘ K

Creating a Branch

Explore how to create and manage branches in Git to handle separate lines of development. Learn commands to initialize repositories, add commits on multiple branches, and use git log to visualize branch history. Understand the relationship between branches and the HEAD to effectively work with parallel changes.

Creating a Git repository

You will create a Git repository with a single file. This file will have separate changes made on two branches: master and newfeature.

Type the following command to create a simple Git repository:

1	mkdir lgthw_git_branch_1
2	cd lgthw_git_branch_1
3	git init
4	echo newfile > file1
5	git add file1
6	git commit -m 'new file1'
7	git status
Terminal 1
Terminal
Loading...

The git branch command

To create a new branch, type the following commands:

8	git branch newfeature
9	git status
10	git branch
Terminal 1
Terminal
Loading...

Now you have created a branch called ...