Reputation: 177
I am quite new to Git. I have a bitbucket repo that I need to work on. The workflow is such that I have to create a new branch on the remote, and then pull that down locally. Lets say the remote branch is named new_branch. This what I am doing:
git init
git pull repo new_branch
# edit files
git add .
git commit -m "some changes"
Form here, I am confused as to how to proceed. I am not creating a branch locally, just working on master. I need to push the changes to and only to remote new_branch. Do i do
git push origin new_branch
Unfortunately, this gives me the error
error: src refspec new_branch does not match any.
error: failed to push some refs to 'origin'
Please tell me what I am doing wrong here. Thanks.
Upvotes: 4
Views: 10565
Reputation: 5808
git push origin <local_branch>:<remote_branch>
Above command will create a remote branch with name remote_branch, and push the code from local branch as local_branch
Upvotes: 0
Reputation: 177
After doing
git checkout new_branch
git push origin new_branch
using the remote branch name for both, I got it to work.
Upvotes: 3
Reputation: 1324268
Try instead of creating a new branch after fetching the repo.
git init .
git remote add origin /url/bitbucket/repo
git fetch
git checkout -b new_branch origin/new_branch
# add, commit
git push -u origin new_branch
Upvotes: 2