Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push branches to Git

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?

like image 841
PHLAK Avatar asked Jul 02 '09 03:07

PHLAK


People also ask

How do I push all branches to github?

Pushing all branches to default remote Now you would have to push all commits of all branches with git push --all github . To simplify that aswell you can run git push --all github -u once and now all you'll have to do is git push . This will now by default push all branches to the default remote github.

What is publish branch in git?

If you want to push to, pull from, or synchronize using a branch you have created, you must publish the branch. You can still commit to an unpublished branch, but until you publish, you will not be able to send your commits to source control for backup.

How do I push a remote code to a git repository?

To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.


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.

like image 97
Alan Haggai Alavi Avatar answered Oct 07 '22 22:10

Alan Haggai Alavi


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.

like image 44
J-16 SDiZ Avatar answered Oct 07 '22 23:10

J-16 SDiZ


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.

like image 35
mturquette Avatar answered Oct 07 '22 23:10

mturquette


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
like image 36
Rizwan Avatar answered Oct 08 '22 00:10

Rizwan