Reputation: 581
I am using Git, and I have created a new branch (named foo
) on my local (one that doesn't exist on the repository).
I have made some changes to my original project (master) files and committed all those changes in this new branch. Now I would like to push this new branch to the remote repository. How can I do that?
If I just run git push
while I am on the branch foo
, will this push the entire branch to the repo? I don't want my changes to be pushed to master. I just want to push this new branch to the main repository.
Upvotes: 11
Views: 44393
Reputation: 3055
To push a branch onto a remote repository you should use this syntax:
git push (remote) (branch)
Usually the first remote (and often the unique) is named "origin", thus in your case you would run:
git push origin foo
It is usually advisable to run a slightly more complex command:
git branch --set-upstream-to origin/foo
because --set-upstream-to
(abbreviated -u
) sets a tracking on that branch and will allow you to push future changes simply running:
git push origin
Tracking branches are local branches that have a direct relationship to a remote branch. If you’re on a tracking branch and type git pull, Git automatically knows which server to fetch from and branch to merge into. (Git documentation)
Upvotes: 10
Reputation: 19133
Yes. It'll prompt you to set the upstream
. You can set the upstream branch like this:
git branch --set-upstream-to origin/yourbranch
It's same for everything except for the branch name. Follow the on screen guidelines.
Upvotes: 11
Reputation: 1473
checkout in to your local branch and use: git push -u origin <branch>
.
this will create the new branch at the remote and push all the changes
Upvotes: 3
Reputation: 320
use git remote -v
to show your remote repo name and url:
origin ssh://**/*.git (fetch)
origin ssh://**/*.git (push)
origin is your remote repo name at local: You can use this command to push your new branch to origin remote repo:
git push origin [your-branch-name]
Like this:
git push origin foo
Upvotes: 1
Reputation: 6458
If the upstream is defined OK, run the following command:
git push origin foo:foo
Upvotes: 1