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.
Please let me know as I do not want to screw up my existing master branch.
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
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.
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.