Push branches to Git

98,660

Solution 1

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.

Solution 2

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.

Solution 3

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,

[email protected]: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.

Solution 4

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
Share:
98,660
warnabas
Author by

warnabas

Passionate PHP developer Penguin Linux junkie Desktop computer Avid PC gamer Coffee aficionado Woman and man holding hands Dedicated husband Family (man, girl, boy) Proud father of two

Updated on February 24, 2020

Comments

  • warnabas
    warnabas about 4 years

    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.

    What needs to be done to accomplish this?

    If this is not possible using GitHub, I'd be happy to know how to do it normally.

    • Michael Durrant
      Michael Durrant over 11 years
      More info on workflow at: stackoverflow.com/a/9204499/631619
    • Monica Heddneck
      Monica Heddneck about 6 years
      not the most insightful title for a question, ugh
  • warnabas
    warnabas almost 15 years
    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.
  • warnabas
    warnabas almost 15 years
    Does that mean I can then do "git pull origin <REMOTE-branch-name>:<LOCAL-branch-name>"?
  • Alan Haggai Alavi
    Alan Haggai Alavi almost 15 years
    @PHLAK: Yes, you can use the same refspec for git pull as well.
  • Slipp D. Thompson
    Slipp D. Thompson about 12 years
    @AlanHaggaiAlavi But that's not the same refspec.
  • Dmitri Zaitsev
    Dmitri Zaitsev about 6 years
    "git pull origin branch_name" - this does seem to pull into a new local branch if there were not any