DEV Community

Elayaraj C
Elayaraj C

Posted on

DAY 5 Git rebase, Git stash, Git cherry-pick.

Create the new file in git directory using git touch command.
$ touch
git rebase Command

The git rebase command is used to reapply commits on top of another base commit, helping to maintain a clean and linear project history.
Basic Usage:

git rebase

This moves your current branch’s commits on top of the .

Lets you edit, squash, or reorder the last 3 commits.

Abort a Rebase (If Something Goes Wrong)

git rebase --abort

Continue After Resolving Conflicts

git rebase --continue

Skip a Commit (If There's an Issue)
$ git --skip

When to Use rebase Instead of merge?

  • Use git rebase when you want a clean, linear history.
  • Use git merge when you want to keep a record of merge commits.

Image description

Uses of Git Branch:

Parallel Development – Multiple team members can work on different features simultaneously without interfering with each other.

Feature Development – Developers can create a new branch to add a feature and merge it later when it's complete.

Bug Fixing – A separate branch can be used to fix bugs without disrupting ongoing development.

Code Isolation – Changes can be tested in a branch before merging into the main branch.

Version Control – Helps maintain different versions of the project for releases or experiments.

Collaboration – Developers can share their branches with others for review before merging.
Enter fullscreen mode Exit fullscreen mode

Common Git Branch Commands

-git branch – Lists all branches.

-git branch <branch-name> – Creates a new branch.

-git checkout <branch-name> – Switches to the specified branch.

-git switch <branch-name> – Alternative way to switch branches.

-git merge <branch-name> – Merges a branch into the current branch.

-git branch -d <branch-name> – Deletes a branch.
Enter fullscreen mode Exit fullscreen mode

git stash Command:

The git stash command is used to temporarily save (stash) changes that are not yet committed, allowing you to switch branches or perform other Git operations without losing your work.

Image description

Common git stash Commands:

git stash – Stashes changes (saves them temporarily).

git stash list – Shows a list of stashed changes.

git stash apply – Reapplies the latest stash without removing it.

git stash pop – Reapplies and removes the latest stash from the list.

git stash drop – Deletes the latest stash without applying it.

git stash clear – Removes all stashed changes.
Enter fullscreen mode Exit fullscreen mode

git cherry-pick Command:

The git cherry-pick command is used to apply a specific commit from one branch into another, without merging the entire branch.

Image description
Common git cherry-pick Commands:

git cherry-pick <commit-hash> – Applies a specific commit to the current branch.

git cherry-pick -n <commit-hash> – Applies changes but does not create a commit.

git cherry-pick --continue – Completes a cherry-pick after resolving conflicts.

git cherry-pick --abort – Cancels an in-progress cherry-pick.
Enter fullscreen mode Exit fullscreen mode

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

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

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay