1

I'm new to git, using svn for many years. I created my master and then from inside the "master" directory created a branch:

git branch Dev
git checkout Dev

But the branch doesnt have any files associated with it. I think its my misunderstanding of git branches. Anybody want to explain? When I create a branch in svn I get a whole repos worth of stuff.

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
mike628
  • 45,873
  • 18
  • 40
  • 57
  • 2
    You created your master and... did you add any files to your repository? (`git add`, `git commit`) – Piotr Findeisen Jun 03 '11 at 19:29
  • 1
    For a bit more background on how Git and SVN handle merging—and by extension, branches—differently, I highly recommend that you [read the answer to this question](http://stackoverflow.com/questions/2471606/how-and-or-why-is-merging-in-git-better-than-in-svn). – Chris Frederick Jun 03 '11 at 19:29
  • @piotr, I think it would still show the files as untracked, not gone... – Jed Schneider Jun 04 '11 at 01:58

3 Answers3

2

Branches are a logical concept in git, they dont exist physically in the file system like subversion. If you want to branch master, you need to type

git checkout -b NEW_BRANCH_NAME

This will create a new branch and set it as your working branch. To switch back to master

git checkout master

You can also see a list of all branches you have by doing

git branch -a
Chris Kooken
  • 32,730
  • 15
  • 85
  • 123
1
git checkout -b dev

checks out a branch of name dev and automatically switches you to it.

git checkout master

moves you back to the main branch

git branch -a 

will tell you all the branches you have

Jed Schneider
  • 14,085
  • 4
  • 35
  • 46
  • I did all the branching , but is this just an empty branch? I figured when I branched master into dev , dev would have the same files? SO I can work on a private version of those files and merge later. I have a master, created a branch, and switched to it... – mike628 Jun 03 '11 at 19:49
  • 1
    yes, when you checkout a branch it creates a branch that is identical to the branch you branched from. what you said you did on the question shouldn't delete any files. try doing a git branch -a to find out what branch you are on. you might benefit from a read at pro-git.org – Jed Schneider Jun 04 '11 at 01:57
0

The concept of branches are almost identical to SVN, but the way they are handled is completely different. Because your repo on your local machine is a full repo, it can have different branches than your remote. You will push and pull branches to and from the remote to get and make changes to branches.

To start a branch off at the head revision of say your 'master' branch, make sure you git checkout master first, then type git branch develop to start a new branch, develop, with the same head revision. Git will alter the filesystem to reflect your new branch.

SamT
  • 10,374
  • 2
  • 31
  • 39