1

I want to push to a branch which is not master. That is what I did:

    git init
    git add .
    git commit -m "first"
    git push origin second (second is the name of a branch) but it say


fatal: origin does not appear to be a git repository.
fatal: could not read from remote repository.
Please sure you have the correct access rights and the repository exists.

Last night I could do that and in the morning suddenly it does not recognize my branch! it does not show my branch when I do git branch, it only shows a master branch. But why I experience this problem sometimes?

Thanks :)

sasha
  • 179
  • 11

2 Answers2

0

First, make sure you are in the right branch: if git branch doesn't list 'second', you can create it:

git checkout -b second

Actually "second" branch exists and I can see it on the github site

Then:

git checkout -b second --track origin/second

(a git fetch origin might be in order first)

Then, make sure the remote 'origin' exists:

git remote -v

And then, push and set origin/second as upstream branch of your local branch second.

git push -u origin second

(See "Why do I need to explicitly push a new branch?" for more)

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Thanks for your reply. Actually "second" branch exists and I can see it on the github site. but it does not recognize it from commands. – sasha Jul 10 '13 at 08:26
  • @sasha if you want to push from your local repo, you need have it first. see my edited answer. – VonC Jul 10 '13 at 08:42
  • Thank you for your answer. Currenlty I am on master branch and I want to push my files in second branch. but it does not recognize my second branch. last time when I did git push origin master. all my file in amster branch replaced by a file that I wanted to added to second branch. and this time I am really scared to to it again. thats why I only want to check out second. but it says could not read from remote repository! – sasha Jul 10 '13 at 08:50
  • @sasha you need first to checkout the second branch, and then add and commit in that branch. What `git remote -v` returns? – VonC Jul 10 '13 at 09:00
0

try

git pull origin master

before

git push origin master

I had the same error and it worked for me.

Jicksy John
  • 159
  • 1
  • 2
  • 13