Home>
Background

I checked out the remote hoge branch as follows and also committed.

>git checkout -b origin/hoge


Now I have a local branch called origin/hoge locally, and after committing, I noticed that I made a mistake in the branch name and tried to reset it, so I deleted the local branch and the tracking branch origin/hoge.

>git branch -D origin/hoge
>git branch -dr origin/hoge


However, I didn't know how to delete remote/origin/hoge, and when I tried to check out the remote branch again, I got the following error.

>git branch -a
* master
remotes/origin/HEAD->origin/master
remotes/origin/hoge
remotes/origin/fuga
...
>git checkout -b hoge origin/hoge
fatal:'origin/hoge' is not a commit and a branch'hoge' cannnot be created from it

Even if I fetch it again, nothing changes, and I am in trouble because I can not check out to the above remote branch with only remotes/origin/hoge remaining.
How can I reset it to its original state?

git
  • Answer # 1

    I checked out the remote hoge branch as follows and also committed.

    checkout -bIs not an operation to check out a remote branch.
    Create a branch with a new name from the current head (latest commit) and checkout (move the current branch) there.

    Also, if remote/origin/hoge exists, it feels like you've pushed as well as committed, right?

    Even if I fetch it again, nothing changes, and I am in trouble because I can not check out to the above remote branch with only remotes/origin/hoge remaining.

    The operation is "Delete the branch in the remote repository".

    Do you know if you look around here?
    https://yu8mada.com/2018/08/13/how-to-delete-both-local-and-remote-branches-in-git/#content-2

    The terminology is confusing overall, so I felt that I wasn't very familiar with how Git works. I feel that you will be able to understand the operation if you investigate the remote repository and local repository a little more.

  • Answer # 2

    It's a brute force, but instead of removing remotes/origin/hoge from the git command and fetching it again, it's direct.
    .git/refs/remotes/origin /
    File hoge

    <Hash value of the latest remote commit>


    I created and reloaded the terminal and was able to check out.
    Maybe it's also a git command. .. ..