Reputation: 3452
I have non empty folder with project. I want to push not to the master but to the branch . How to do this?
cd <folder>
git init
git remote add origin <url> //at this point my folder connected to the master
What should be next?
git branch <branch1>
git add .
git commit -m "commint to branch1"
git push
Upvotes: 1
Views: 69
Reputation: 109100
As you've not done a git fetch
you don't have the changes from the remote in any branches including the one you've created. Assuming you want to use branch1
as the name in the remote. I would suggest
.git
folder somewhere else)Switch to master
git checkout master
Rename your local working branch for the time being
git branch -m branch1 tempBranch
Get the content of the remote locally
git fetch
Ensure your master
is up to date with origin/master
git pull
Create a new working branch and set it up in the origin
git checkout -b branch1
git push -u origin branch1
Put the changes you wanted into the real branch1
git merge tempBranch
you may need to handle conflicts at this point.
Push your changes
git push
Alternatively, if you've only made trivial changes, just start anew with a clean clone of the remote and redo you changes in that new local repository.
Upvotes: 1
Reputation: 665
You can use following commands :
git checkout -b <branch1>
git add .
git commit -m "commint to branch1"
git push -u origin <branch1>
Upvotes: 0