🤓
Thomas lab
Git&Github
Git&Github
  • Fetching & Pulling
  • Git alias
  • Git & Github : What is in .git ?
  • Git Rebase
  • Git reflog
  • Git Stash
  • Git tags
  • Git Workflow(Collaboration)
  • Quick High-Level
  • Git diff
  • Git installer
  • Reset & Revert commit
  • Github Collaborators
  • Github Basics
  • Introducing Git
  • Merging Branch
  • How to use multiple account
Powered by GitBook
On this page
  • Rebasing
  • Why rebase ?
  • Warning
  • Interactive rebase
  • How to using interactive mode

Git Rebase

PreviousGit & Github : What is in .git ?NextGit reflog

Last updated 8 months ago

Rebasing

When i first leaned git , i was told to avoid rebasing ta all costs .

Rebasing . It actually very useful , as long as your know when not to use it

There are two main ways to use the git rebase command :

  • as an alternative to merge

  • as a cleanup up to

We can instead rebase the features branch onto the master branch . This moves the entire feature branch so that is begins at the tip of the feature branch. ALl of the work is still there , but we have re-writen history

instead of using a merge commit . rebasing rewriten history by creating new commits for each of the original features commits

Why rebase ?

We ge a much clearner project history . No unnecessary merge commit! We end up with a linear project history.

Warning

Never rebase commits that have been shared with others. if you have already pushed commits commits up to github.. do not rebase them unless you are positive no one on the team is using those commits

Interactive rebase

Running git rebase with the -i option will enter the interactive mode, which allows us to edit commit, add files,drops commits,etc . Note that we need to s[ecify how far back we want rewriten history .

Also notice that we not rebasing onto antther branhc. Instead,WE are rebasing a sreies of commits onto the HEAD rhey currenly are based on .

How to using interactive mode

In our text editor, we'll see a list of commit alongside a list of commaands that we can choose from. Here are a couple of the more commony use commands:

  • pick - use the commit

  • reword - use the commit, but edit the commit message

  • edit - use commit, but stop for amending

  • fixup - use commit contents but meld it into previous commit and discard the commit message

  • drop - remove commit