Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create branch and push to server

Tags:

git

I have cloned project from repo and I need to create branch and in that branch do my changes. After that I need to push that branch on repo. How to do this ? I am sorry, I am new to git ?

like image 368
Damir Avatar asked Oct 10 '11 11:10

Damir


People also ask

How do I create a new branch?

New Branches The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.


1 Answers

You can create a new branch called my-work (based on your current commit) and switch to that branch with:

git branch my-work
git checkout my-work

Or, as a shortcut for those two commands, you can just do:

git checkout -b my-work

To push that branch to the repository that you cloned from, you should do:

git push origin my-work

origin is a nickname for the repository you cloned from. It's known as a "remote", in git terminology. Update: a clarification due to Michael Minton's helpful comment above: this will push your my-work branch to a branch called my-work in the remote repository, creating it if necessary - if you meant something different, it would be best to edit your question to clarify that point.

The first time you do that push command, you may want to do git push -u origin my-work, which sets configuration options that make the branch my-work in the origin repository considered as the default "upstream" branch for your my-work branch. (You don't need to worry about that for the moment if you're new to git, but it will mean that git provides more helpful status information and various commands have more useful default actions.)

like image 96
Mark Longair Avatar answered Oct 13 '22 00:10

Mark Longair