2

As a git beginner, I am having the worst time with this. If this question was asked before, then I apologize--but I cannot find any Stack Overflow page that gives me the answer I need. That being said, here is my question:

What are all the steps required to locally push to a branch on GitHub given the branch url? Specifically, how do you make the repo point at the correct location after initialization?

So far I have tried:

git init
git remote add <branch_name> <url_of_branch>
git add .
git commit -m "Message"
git push origin <branch_name>

Along with numerous other attempts. The error message I have been getting is:

error: src refspec <branch_name> does not match any.
error: failed to push some refs to 'git@github.com:<username>/path/to/rep

Thank you for your help!

schro's cat
  • 119
  • 4

1 Answers1

1

Try creating the local branch first (instead of git remote):

git checkout -b <branch_name>

Then add, commit and push while setting an upstream branch:

git push -u origin <branch_name>

Confirm with git branch -avv to see both your local branch and its upstream remote tracking branch origin/<branch_name>

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250