Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push a new branch in git? [duplicate]

Tags:

git

terminal

Checked out master branch, made changes. How now to create a new branch, commit changes, and push it to the remote?

like image 428
DuckQueen Avatar asked Sep 08 '18 01:09

DuckQueen


People also ask

Can you push to another branch in git?

Push Branch to Another Branch In some cases, you may want to push your changes to another branch on the remote repository. In order to push your branch to another remote branch, use the “git push” command and specify the remote name, the name of your local branch as the name of the remote branch.

How do I copy a branch to another branch?

In order to clone a specific branch, you have to execute “git branch” with the “-b” and specify the branch you want to clone. $ git clone -b dev https://github.com/username/project.git Cloning into 'project'... remote: Enumerating objects: 813, done.


1 Answers

Four steps to get your changes committed locally and get them pushed to your server:

Create a local branch and commit to it

git checkout -b your-shiny-branch
git add .
git commit -m "Your Message"

Push your branch to your remote (server)

git push -u origin your-shiny-branch

If you then need to do further commits, start from command #2 and omit the -u flag during the git push on step #4.

like image 148
everton Avatar answered Oct 09 '22 20:10

everton