
If we need to restore a deleted branch we can use git checkout -b. We either have to perform a commit first or use the option -D instead of -d. However, this will not be possible if the branch contains uncommitted changes. To delete a branch we type git branch -d. Any modifications we commit now will be added to that branch. Instead, it tracks the commit history of the chosen branch and reproduces the changes in our repository.
#Git delete branch with uncommitted changes full#
Keep in mind that a git checkout is not like a git clone operation and therefore does not make a full copy of a different code branch. Naturally, this also happens when we want to switch to a branch with different contents than in hour current branch. This can happen if we make changes to our repository (like Adding or Modifying files), but do not commit them before switching the branch. Line 2 informs us about a Modified file named "someFile". To view all existing branches use the git branch -list command:Ģ M someFile 3 Switched to branch 'branchingTut' 4 git branch -aĥ * branchingTut 6 main 7 remotes/origin/main A so-called pull request must be made, so that a responsible person can pull your changes from your branch and merge them into "main". In larger projects this merge ing into the "main" branch is often blocked for most users. Even when differences do not directly interfere, they can still lead to a more cumbersome merge of both branches into "main", once all changes are complete. When developing new features you do not necessarily want to directly commit your changes to "main", because they might interfere with your colleagues contribution of other features on a different branch. As the name implies, branching refers to the creation of a separate line of repository tracking that branches of from your "main" repository (also called a branch, but can be understood as the trunk). Unlike the green branch, the orange/brown/purple branch continues to exist, because its purple features are still expanded and will later be merged again into the main branch.īranching is an important feature of Git, which enables simultaneous work on different parts of a code with minimal interference between acting parties. At this point the main branch will contain contributions from all branches. Later, a merge operation combines the orange/brown and orange/purple branch together and subsequently those orange/brown/purple changes are merged into the main branch as well.


Instead of directly merging the orange branch into the main branch it continues development on some light purple features while in parallel some brown features are added to orange (e.g., solving bugs in orange code). When development is finished, a new branch is created from this branch. On the other side, the orange segment is developed simultaneously. Once the green segment is finished, its contribution is merged into the main branch and work on the green segment branch stops. Theses branches can both belong to one or to two different developers. Two independent developments occur on those new branches visualized by the different colors green and orange. Initially, two branches are created from the main branch. The figure can show a local or a remote repository omitting depictions of commit and push operations to keep it simple (they happen somewhere on the dashed lines). Figure 1: Example of basic workflow with branching.
