GIT Practical Reference

Managing Branches

Creating a New Branch

To create a new branch, with your desired , use the git branch command:

git branch <new_branch_name>

By default, this command creates a new branch based on your current branch.

Switching to a Branch

To switch to a different branch, use the git checkout command followed by the branch name:

git checkout <branch_name>

This command will make your working directory reflect the state of the specified branch.

Creating and Switching in One Step

You can create and switch to a new branch in one step using the -b flag with git checkout:

git checkout -b <new_branch_name>

Renaming a Branch

To rename a branch, you can use the -m option with git branch:

git branch -m <new_branch_name>

Deleting a Branch

To delete a branch, first make sure you are not on the branch you're trying to delete, then use the -d option with git branch:

git branch -d <branch_name>

If the branch contains unmerged changes, Git will prevent deletion. You can force deletion with -D:

git branch -D <branch_name>