DEV Community

shun
shun

Posted on • Edited 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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay