jrlmx2
jrlmx2

Reputation: 1987

git rebase fatal: Needed a single revision

I have a branch of a public repository and I am trying to update my branch with the current commits from the original repository:

$ git fetch <remote>
remote: Counting objects: 24, done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 20 (delta 12), reused 0 (delta 0)
Unpacking objects: 100% (20/20), done.
From git://github.com/path_to/repo
  9b70165..22127d0  master     -> $/master
$ git rebase <remote>
fatal: Needed a single revision
invalid upstream <remote>

The <remote> is in place of my remote name and is not actually my remote name. The documentation on this error seems to be a bit loose.

Upvotes: 192

Views: 327399

Answers (8)

Mario Olivio Flores
Mario Olivio Flores

Reputation: 2765

I ran into fatal: Needed a single revision and realized I didn't fetch the upstream before trying to rebase. All I needed was to git fetch upstream first.

Upvotes: 31

MeadowMuffins
MeadowMuffins

Reputation: 527

For me, to specify branch helps.

  1 [submodule "test/gtest"]
  2     path = test/gtest
  3     url = ssh://[email protected]/google/googletest.git
  4     branch = main

Upvotes: 2

Birbal Sain
Birbal Sain

Reputation: 31

$ git rebase upstream/master

fatal: Needed a single revision

invalid upstream usptream/master**

So I tried $ git rebase remotes/upstream/master and it works for me.

Upvotes: 0

Jani
Jani

Reputation: 911

The error occurs when your repository does not have the default branch set for the remote. You can use the git remote set-head command to modify the default branch, and thus be able to use the remote name instead of a specified branch in that remote.

To query the remote (in this case origin) for its HEAD (typically master), and set that as the default branch:

$ git remote set-head origin --auto

If you want to use a different default remote branch locally, you can specify that branch:

$ git remote set-head origin new-default

Once the default branch is set, you can use just the remote name in git rebase <remote> and any other commands instead of explicit <remote>/<branch>.

Behind the scenes, this command updates the reference in .git/refs/remotes/origin/HEAD.

$ cat .git/refs/remotes/origin/HEAD 
ref: refs/remotes/origin/master

See the git-remote man page for further details.

Upvotes: 2

Deepesh Panjabi
Deepesh Panjabi

Reputation: 1

git submodule deinit --all -f worked for me.

Upvotes: 0

ChrisJF
ChrisJF

Reputation: 7190

Check that you spelled the branch name correctly. I was rebasing a story branch (i.e. branch_name) and forgot the story part. (i.e. story/branch_name) and then git spit this error at me which didn't make much sense in this context.

Upvotes: 36

Maitreya
Maitreya

Reputation: 1266

The issue is that you branched off a branch off of.... where you are trying to rebase to. You can't rebase to a branch that does not contain the commit your current branch was originally created on.

I got this when I first rebased a local branch X to a pushed one Y, then tried to rebase a branch (first created on X) to the pushed one Y.

Solved for me by rebasing to X.

I have no problem rebasing to remote branches (potentially not even checked out), provided my current branch stems from an ancestor of that branch.

Upvotes: 12

CB Bailey
CB Bailey

Reputation: 791421

You need to provide the name of a branch (or other commit identifier), not the name of a remote to git rebase.

E.g.:

git rebase origin/master

not:

git rebase origin

Note, although origin should resolve to the the ref origin/HEAD when used as an argument where a commit reference is required, it seems that not every repository gains such a reference so it may not (and in your case doesn't) work. It pays to be explicit.

Upvotes: 165

Related Questions