Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Git's interactive rebase with a local-only repository (no remote / origin)?

I use git as a local source control system mostly for history and diff tracking. I still want to use rebase to do fixup / squash on WIP commits that I will make periodically. When I try to do git rebase -i though, I get the following:

There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
See git-rebase(1) for details

    git rebase <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=<remote>/<branch> MyBranch

It seems like git doesn't expect you to use interactive rebase without an upstream remote? How do I do that?

like image 993
mcw Avatar asked Jun 03 '15 16:06

mcw


People also ask

How do I rebase locally?

To rebase a branch, checkout the branch and then rebase it on top of another branch. Important: After the rebase, the applied commits will have a different hash. You should not rebase commits you have already pushed to a remote host.

How do I use git interactive rebase?

You can run rebase interactively by adding the -i option to git rebase . You must indicate how far back you want to rewrite commits by telling the command which commit to rebase onto. Remember again that this is a rebasing command — every commit in the range HEAD~3..

How do I rebase locally Orcode?

Let's Begin! Once you have your commits ready, we can click the Start Rebase button. You will then be presented with a screen in VS Code to reword your commit message. Write your new message, and save and close the file to continue. After this, our rebase is complete.


2 Answers

git rebase -i in shorthand, without specifying a destination branch, will make git assume that you are trying to rebase against a remote branch tracked by your branch. That's why the error message is mentioning stuff about remotes.

When you do specify a target, git will rebase against that commit-ish:

git rebase -i <commit-ish>
like image 151
Sébastien Dawans Avatar answered Oct 10 '22 07:10

Sébastien Dawans


So in short - if you have 3 local commits and you now want to interactively rebase/squash/etc them:

git rebase -i HEAD~3

(See Sébastien's explanation !)

like image 28
MikeW Avatar answered Oct 10 '22 07:10

MikeW