12

I'm learning Git and experimenting. I understand how to do basic operations but am struggling with creating a new branch. I'm using the command prompt in windows and the github tool in a browser. I have attempted to simulate the creation of a new branch by making a new branch (named branch_1) in the browser, but when I try to find that branch in the command prompt, it does not show up. For example, here's what I get in the command prompt:

git branch _notes/dwsync.xml master v1.1 v1.2 v1.3 

How do I get the new branch to appear?

1
  • The browser creates the branch directly in the remote github project. Not in your working copy. Use git pull to synchronize the working copy with the changes made in the remote repo. You should usually do the reverse: create your branch locally using the command line, make changes in your branch, commit, and push the branch. Commented Oct 28, 2016 at 15:10

5 Answers 5

11

You do these steps:

git checkout -b your_branch git push -u origin your_branch 

show all branches (see result):

git branch 

Reference: https://git-scm.com/docs/git-branch

Sign up to request clarification or add additional context in comments.

Comments

5

When you create a branch in github, it's in the github remote. You need to fetch the branch from that remote, to your local, and tell your local to track that branch.

git fetch <remote_name> <branch_name>

git checkout --track <remote_name>/<branch_name>

This assumes you want the branch_name on the remote to be the same on your local.

Comments

2

A branch is a lightweight thing in git, it is just a sticky note pointing to a commit. Actually, it is even lighter than a tag (which has additional attributes).

You normally create branches locally. If you want to create a branch newbranch starting off at oldcommit (which can, as always, be a commit hash, a branch name, a tag name or some other more obscure things), then you basically have two equivalent ways of doing that:

git checkout oldcommit git checkout -b newbranch 

or

git branch newbranch oldcommit git checkout newbranch 

It's a matter of taste, I prefer the first one.

To push the branch to the remote origin:

git push origin newbranch 

I suggest you get very familiar with working with branches, you will be doing it all the time, and it should really feel easy and spontaneous to you. This is one of the major benefits of using git over other versioning systems.

Comments

0

when you create a new branche in github with the browser you must pull it in your local repo so you do : git pull and after you execute : git branch

Comments

0

git checkout -b 'branchname'

this will create a new branch and transfer you there from the master

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.