![]() ![]() This protects you from losing your reference to those commits, which means you would effectively lose access to that entire line of development. If you are sure you want to delete it, run 'git branch -D crazy-experiment'. However, if the branch hasn’t been merged, the above command will output an error message: error: The branch 'crazy-experiment' is not fully merged. Once you’ve finished working on a branch and have merged it into the main code base, you’re free to delete the branch without losing any history: git branch -d crazy-experiment Please see the git checkout section of this module for more information. To start adding commits to it, you need to select it with git checkout, and then use the standard git add and git commit commands. Note that this only creates the new branch. All you get is a new pointer to the current commit: The repository history remains unchanged. Then, you create a branch using the following command: git branch crazy-experiment So, if you start with a repository that looks like this: When you create a branch, all Git needs to do is create a new pointer-it doesn’t change the repository in any other way. It's important to understand that branches are just pointers to commits. You can actually see merges in the project history as a joining of two independent commit histories. Whereas merges in SVN are done on a file-basis, Git lets you work on the more abstract level of commits. This has a dramatic impact on Git's merging model. The history for a branch is extrapolated through the commit relationships. In this sense, a branch represents the tip of a series of commits-it's not a container for commits. Instead of copying files from directory to directory, Git stores a branch as a reference to a commit. The implementation behind Git branches is much more lightweight than SVN’s model. By developing them in branches, it’s not only possible to work on both of them in parallel, but it also keeps the main master branch free from questionable code. This makes sure that unstable code is never committed to the main code base, and it gives you the chance to clean up your feature’s history before merging it into the main branch.įor example, the diagram above visualizes a repository with two isolated lines of development, one for a little feature, and one for a longer-running feature. When you want to add a new feature or fix a bug-no matter how big or how small-you spawn a new branch to encapsulate your changes. In Git, branches are a part of your everyday development process. This is the command to use if you want to permanently throw away all of the commits associated with a particular line of development. git branch -D įorce delete the specified branch, even if it has unmerged changes. This is a “safe” operation in that Git prevents you from deleting the branch if it has unmerged changes. git branch -d ĭelete the specified branch. ![]() List all of the branches in your repository. For this reason, git branch is tightly integrated with the git checkout and git merge commands. It doesn’t let you switch between branches or put a forked history back together again. The git branch command lets you create, list, rename, and delete branches. New commits are recorded in the history for the current branch, which results in a fork in the history of the project. You can think of them as a way to request a brand new working directory, staging area, and project history. Branches serve as an abstraction for the edit/stage/commit process discussed in Git Basics, the first module of this series. git branchĪ branch represents an independent line of development. Whereas SVN branches are only used to capture the occasional large-scale development effort, Git branches are an integral part of your everyday workflow. Finally, we'll learn how git merge can integrate the history of independent branches.Īs you read, remember that Git branches aren't like SVN branches. Then, we'll see how git checkout can be used to select a branch. First, we'll take a look at creating branches, which is like requesting a new project history. This tutorial is a comprehensive introduction to Git branches. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |