Skip to content

Latest commit

 

History

History
79 lines (60 loc) · 2.83 KB

branches.md

File metadata and controls

79 lines (60 loc) · 2.83 KB

Git Branches

Branching is Git's killer feature. Branches allow you to diverge from the main line of development and continue to do work without messing with that main line.

Rename default branch

Renaming your default branch from master to main is a common modern setup step. #setup #init #master #main

git branch -M main

Switch branches

Moving between different branches updates your working directory to match the commit at the tip of that branch. This interactive command shows you the commit subject alongside the branch name so you know exactly what work is on that branch before you switch to it. #checkout #switch

git switch $branch

Create and switch to a new branch

When you start working on a new feature or bugfix, you should create an isolated branch. This creates the branch and immediately checks it out.

git switch -c $new_branch

Delete a branch

Deleting a branch removes the pointer to the commit, but the commits themselves might still exist until garbage collected. This command safely deletes the branch only if it has been merged. #rm-branch #remove

git branch -d $branch_del

Rename a branch

Rename an existing local branch. #mv-branch #rename

git branch -m $branch $new_branch

Merge a branch into current branch

Merging integrates the history of one branch into another. You can choose to fast-forward if possible, force a merge commit (--no-ff) to preserve the feature branch history, or squash everything into a single commit on the target branch. #combine #join

git merge $merge_flags $branch_merge