I have a local repository I'm working on and its remote is hosted on GitHub. I recently created a branch and started working on it, making several commits and now wish to push the branch to GitHub and be able to pull it to another cloned repository. How do I do this?
4 Answers
git push origin <local-branch-name>:<remote-branch-name>
Substitute for <local-branch-name>
and <remote-branch-name>
. They may be same or different, as you wish.

- 72,802
- 19
- 102
- 127
-
2
-
4@PHLAK: Yes, you can use the same refspec for `git pull` as well. – Alan Haggai Alavi Jul 02 '09 at 03:58
-
As you have set up the remotes already, the command is just
git push origin branch-name
on the first push.
Afterward, using git push origin
would push all branches with the matching name on remote.

- 30,738
- 21
- 105
- 131

- 26,473
- 4
- 65
- 84
Make sure that your remote URL is using SSH syntax and not just Git protocol syntax. If you run,
git remote show origin
the URL printed should look something like,
git@github.com:yourname/projectname.git
You need the URL too to look like that if you want to be able to push. If you are just a public user (without write access) the URL will look like,
git://github.com/yourname/projectname.git
If yours looks like the latter then you can manually edit it in your projects .git/config
file.

- 30,738
- 21
- 105
- 131

- 2,067
- 1
- 11
- 3
-
I can already push and pull to and from my GitHub repo, I'm just trying to figure out how to push and pull a branch. – PHLAK Jul 02 '09 at 03:39
if you need to pull any branch code from remotely to locally
$git pull origin branch_name
while if you need to push code to your branch
you need to check is your code successfully save you can check by
$git status
than
$git add -A
after this make commit to your branch
$git commit -m "this is initial change"
than(Last) push your code to your branch by:
$git push origin branch_name

- 3,741
- 2
- 25
- 22
-
"git pull origin branch_name" - this does seem to pull into a new local branch if there were not any – Dmitri Zaitsev Apr 25 '18 at 03:17