Wednesday, June 5, 2013

How to create a new git local branch and push to repository (remote/origin)

From your terminal using commands
Check your git version with the following command,
git --version
if you have git version equal or greater than 1.7.0, you should be able to do with the following commands.
git checkout -b newbranch

git push -u origin newbranch
The first command creates a new branch from your current local branch. In order find what's your current branch use the command "git branch -a". It will list all available branches, the current branch will be preceded with a *.
The "-u" option is available only from git 1.7.0. It refers to "upstream" to where you want to push to or pull from.

From eclipse
Right click on your eclipse project Team -> Switch to -> New branch.

Create branch from eclipse

Give your new branch name in the following dialog and then click Finish. This will create a new branch from your current working branch.

Make all your changes to the new branch, to push the newly created branch right click Team -> Commit & Push (EGit2.x versions).

From github
The simplest way to create a new branch is from Github. If you have push access to the repository, start typing the new branch name in the search box of switch branches/tags. This box will appear once you click on the down arrow near branch. Once you complete typing the branch name, you will see an option to create new branch with the name provided. Click on it, you are done.

Create branch from github

submit to reddit

No comments:

Post a Comment