Q: git creating a branch from the master I am new to using git and come from SVN background. I have checkout a project containing all the files in the default master branch. All the files in the master branch are outdated and I need to checkin a new set of files. But I am planning to create a new branch for the same and continue my development in the branch. 


*

*Do I need to be in the master branch to create a new branch?

*Command to create a new branch so that the master branch is untouched.

*How to switch to the master/mybranch branch later.

*Command to know which branch I am currently working on?


Please let me know as I do not want to screw up my existing master branch.

A: 1: I think you can be in whatever branch you want.
2: git checkout -b newbranch, this create and change to the new branch
3: git checkout branchtoChange
4: git branch
Also, take a look to the link @dalen post in the comment. Some time ago I created a cheatSheet of git based on that book, Git scm

A: *

*You can be in any branch when creating a new branch. The point is, when you create a new branch, it will fork the new branch from your current branch only.

*git checkout -b newBranchName

*git checkout branchNameToSwitch

*git branch. It will list all the branches in your local repository. Your current branch will be marked with * . You can also use git branch -a to list remote branches as well.


You can refer to this GitHub forum as well for basic branching and merging concepts.

A: *

*Yes if you need changes from master, you need to checkout in new branch from master.

*You can create branch using two approaches

git branch <branch name>
git checkout <branch name>


OR
git checkout -b <branch name>



*

*git checkout  makes you switch to different branches.

*When you run git branch you will get all branch names with asterstik on it.
Thanks

A: 1) Yes, if you wish to create a new branch from the master branch then you need to be in master branch. The point is, when you create a new branch B by being in any branch A, it will create the branch B with the contents you have updated to till date in branch A.
2) 
The command to create a new branch,
git branch NewBranchName,
git checkout NewBranchName
(or)
git checkout -b NewBranchName (It will create a new branch and checkout to the new branch in a single command)
Then push the new branch to the remote by the following command,
git push origin master
3)
git checkout NewBranchName (switches to NewBranchName branch when you are in any branch)
or 
git checkout master (switches to master when you are in any branch)
4) 
git branch
The pointer * represents that, In which branch you are right now.
