1

It is kinda complicated situation

I am really new to github and its workflow concept. Yesterday, I started a project on local and pushed it to my remote. The default branch name was railsAPI. Then i tried to change the branch's name to master, however, I messed up at this part. The branch name in my local machine is changed, but the name of the branch stayed the same on GitHub. So i decided to create a new branch called master, set it as default branch and delete the railsAPI branch.

On GitHub, everything looks fine. However, on my local machine, when ever i type git status, the following message shows up:

On branch master
Your branch is ahead of 'origin/railsAPI' by 2 commits.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean

I can still add, commit and push just fine. but the fact that there exist a ghost branch on my local machine and every time I make a change, the master branch will be one more commit ahead of that ghost branch.

what I have tried: I tried to do git pull to synch with my Github, however, i got following message:

Your configuration specifies to merge with the ref 'refs/heads/railsAPI'
from the remote, but no such ref was fetched.

I tried to search on SO, but i believe my situation is different from other similar questions since that branch has been deleted, so i don't think it is a duplicate question

What I need help with : How do I clean my local repo and what caused this strange behavior?

ZpfSysn
  • 807
  • 2
  • 12
  • 30

1 Answers1

3

You may have deleted the remote branch railsAPI on GitHub, but there is still a remote-tracking branch called origin/railsApi in your local repo, and your local masterbranch is still set to track it.

You need to change the branch that your local master branch is tracking to be the master branch on GitHub:

git branch --set-upstream-to=origin/master master

You may also want to delete the remote-tracking branch left behind in your repo:

git branch -d -r origin/RailsApi
jub0bs
  • 60,866
  • 25
  • 183
  • 186
  • Thanks. Now i wonder, after i changed the name of my local branch, what should do I so that the remote branch will also change accordingly? – ZpfSysn Jan 11 '18 at 13:40
  • @aDev I'm not sure I understand the question... Could you clarify? – jub0bs Jan 11 '18 at 13:45