I created a local branch which I want to \'push\' upstream. There is a similar question here on Stack Overflow on how to track a newly created remote branch.
Howeve
Easiest Solution... Drumm Roll... git version 2.10.1 (Apple Git-78)
1) git checkout -b localBranchNameThatDoesNotExistInRemote
2) Do your changes, and do a git commit
3) git push origin localBranchNameThatDoesNotExistInRemote --force
N.B. - The branch you just created in your local environment, and the remote non-existing branch where you are trying to push, must have the same name.
As stated in the previous answers,
git push <remote-name> <local-branch-name>:<remote-branch-name>
is enough for pushing a local branch.
Your colleagues, can pull all remote branches (including new ones) with this command:
git remote update
Then, to make changes on the branch, the usual flow:
git checkout -b <local-branch-name> <remote-name>/<remote-branch-name>
Create a new branch locally based on the current branch:
git checkout -b newbranch
Commit any changes as you normally would. Then, push it upstream:
git push -u origin HEAD
This is a shortcut to push the current branch to a branch of the same name on origin and track it so that you don't need to specify origin HEAD in the future.
If you want to create a branch from the current branch
git checkout -b {your_local_branch_name}
you want a branch from a remote branch, you can try
git checkout -b {your_local_branch_name} origin/<remote_branch_name>
If you are done with changes you can add the file.
git add -A or git add <each_file_names>
Then do a commit locally
git commit -m 'your commit message'
When you want to push to remote repo
git push -u origin <your_local_branch_name>
All together will be
git checkout -b bug_fixes
or If you want to create a branch from a remote branch say development
git checkout -b bug_fixes origin/development
You can push to the branch to remote repo by
git push -u origin bug_fixes
Anytime you want to update your branch from any other branch say master.
git pull origin master.
If you wanna actually just create remote branch without having the local one, you can do it like this:
git push origin HEAD:refs/heads/foo
It pushes whatever is your HEAD to branch foo that did not exist on the remote.
How to do through Source Tree
1: Open SourceTree, click on Repository -> Checkout
2: Click on Create New Branch
3: Select the branch where you want to get code for new branch
4: Give your branch name
5: Push the branch (by click on Push-button)