Reputation: 154
After cloning a repository I cannot reset that repository's state to a remote branch.
$ git clone <repo>
$ git reset --hard <upstream branch>
fatal: ambiguous argument '<upstream branch>': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]
What works fine is either prefixing with origin
$ git reset --hard origin/<upstream branch>
or do a checkout before
$ git checkout <upstream branch>
$ git reset --hard <upstream branch>
Questions:
Upvotes: 5
Views: 7536
Reputation: 7002
Git cannot find a reference to a branch named upstream_branch
in your fresh local repo, because it doesn't exist. But the reference for origin/upstream_branch
does exist. Run git branch --all
and you'll see the full list of branches in your repository, both local and remote.
In the second working scenario, when you run git checkout upstream_branch
you created a local branch named upstream_branch
set up to track remote branch origin/upstream_branch
. That's why the subsequent git reset
command works.
Upvotes: 3
Reputation: 10947
What do you mean by "reset that repository's state to a remote branch" ?
If you want a local branch equal to the remote branch just use **git checkout*:
git checkout -b local_branch_name origin/remote_branch_name
If you have a dirty workspace, and you want to get rid of any added/modified file you can type:
git clean -f
git checkout -f -b local_branch_name origin/remote_branch_name
Upvotes: 0