![]() ![]() Suppose you have uncommitted changes to a tracked file when you try to switch branches. To switch to commander, simply use : $ git checkout commander Suppose you have two branches named master and commander, and youâre currently on master. git checkout does all of these things, and more. Technically, you could update the HEAD ref directly with git update-ref, but this isnât usually done and would be very confusing by itself normally, you want your working tree and index to match the new branch tip when you switch branches, taking into account any uncommitted changes you may have. Here, git symbolic-ref HEAD shows the ref (branch name) to which HEAD points: $ git symbolic-ref HEAD The HEAD by definition indicates the branch that you are âon,â and switching to a branch means that you are then âonâ that branch. The only thing that has to happen to switch branches is to change the HEAD symbolic ref to point to the new branch name. The usual tool for switching branches is git checkout, of which the -b option given previously is just a special case: switching to a branch that doesnât yet exist is creating a new branch. When you make your first commit, Git will create the master branch with it. However, a branch name is just a ref pointing to the latest commit on the branchâand there are no commits yet in this new, empty repository, and so there is no master branch ref yet. Git has initialized the HEAD ref to point to master, making master the current branch. ![]() The error message is technically correct, though. Git could be more helpful here, since getting a âfatalâ error with a newly created repository strongly suggests that something is broken. Initialized empty Git repository in /u/res/zork/.git/ If you try to use the master branch in a brand-new repository, however, youâll get perhaps unexpected results for example: $ git init The master branch is conventionally used if there is only one branch in a repository, or if there are several but there is a single, clear main line of development. There is nothing special about this name aside from being used as a default, and you can rename or delete it if you like. Some of these are used in the development of Git itself.Ī new Git repository created with git init has a single branch with the default name master. The man page gitworkflows(7) presents several branching disciplines that may be directly useful, or give you ideas on how to structure your own projects in other ways. Product development continues, but you may need to apply bug fixes or new features to that version even after youâve released 2.0, for customers who are still using the older version the 1.0 branch allows you to do that (and git cherry-pick is particularly useful in this case see git cherry-pick). When you release version 1.0 of your product, it gets its own branch. When the feature is ready, you do the opposite: merge the feature branch into master, adding the new code to the main version of the project.Īnother use for multiple branches is to continue maintenance on older versions of software. Periodically, you merge master into your feature branch, so youâre working on up-to-date code and notice and resolve any conflicts. You work on the feature branch while developing that feature, and switch to the master branch to work on the main project (which does not yet contain the new feature code). Branches allow different versions of the same content to evolve independently at the same time, while you periodically recombine the contributions from different branches in a process called âmerging.â When you switch from one branch to another, Git updates your working tree to reflect the state of the repository content in the tip commit of the new branch.Ī typical use for a branch is to work on a new software feature in isolation, without adding it to the main line of development of the project these are often called âfeatureâ or âtopicâ branches. Now that you know how to create a repository and commit to a single branch, itâs time to learn about using multiple branches.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |