41

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?

mcw
  • 3,500
  • 1
  • 31
  • 33
  • simply use `$ git rebase -i HEAD~4` ref [What does it mean to squash commits in git?](https://stackoverflow.com/questions/35703556/what-does-it-mean-to-squash-commits-in-git/50443893#50443893). Here "HEAD~4" means to specify the commits as using the last four commits from where the HEAD is. – tinystone Aug 30 '22 at 05:55

2 Answers2

40

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>
Sébastien Dawans
  • 4,537
  • 1
  • 20
  • 29
  • 1
    You can track any branch, local or remote. – jthill Jun 03 '15 at 18:01
  • Yeah - tried to edit the answer to point that out, because I basically re-edited my original self answer to be the same. `HEAD~3` here is not an essential part of the syntax, it's just one (of any) possible `commit` refs. – mcw Jun 03 '15 at 19:40
  • 1
    `HEAD~3` is only there because your original answer attemps to rebase on `HEAD~3`, and going through unnecessary steps to acheive it. I can put commit-ish if you prefer... – Sébastien Dawans Jun 03 '15 at 20:06
  • 1
    This answer should explain what "commit-ish" means or at least link to it like mcw0933's comment on the other answer – reggaeguitar Oct 22 '18 at 22:02
25

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 !)

MikeW
  • 5,504
  • 1
  • 34
  • 29
  • 1
    Yup - thanks @MikeW. That is one concrete example of what you can use for the "commit-ish" parameter to git. For anyone unfamiliar with what a "commit-ish" is... check out this other SO answer: http://stackoverflow.com/questions/23303549/what-are-commit-ish-and-tree-ish-in-git – mcw Nov 29 '16 at 02:00