DEV Community

shun
shun

Posted on • Updated on

Git Commands Mastering Basics, Merge, and Rebase

Group Changes

Lists all local branches in the current repository

git branch
Enter fullscreen mode Exit fullscreen mode

Creates a new branch

git branch [branch-name]
Enter fullscreen mode Exit fullscreen mode

Switches to the specified branch and updates the working directory

git checkout [branch-name]
Enter fullscreen mode Exit fullscreen mode

Combines the specified branch’s history into the current branch.

This command is used when you want to combine changes from two different branches. It creates a new "merge commit" in the branch that preserves the history of both branches.

git merge [branch]
Enter fullscreen mode Exit fullscreen mode

Deletes the specified branch

git branch -d [branch-name]
Enter fullscreen mode Exit fullscreen mode

Rebase

The git rebase command moves or combines a sequence of commits to a new base commit. Essentially, it's a way to integrate changes from one branch into another, but it differs from merge by rewriting commit history. Use it carefully, as it can complicate the commit history and is not recommended if you're working on a public branch that others are using.

git rebase [base]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)