![]() ![]() What this will cause the switch will bring the ComponentTwo.js file with it to branch2. This won't cause any conflict as branch-2 doesn't have the file. And now, before committing or stashing we switch to branch2. ✅ git switch branch1 -> make changes -> git commit -a -m "commit message" -> git switch branch2īUT if a file named ComponentTwo.js is only present in let's say branch1, we make some changes to save them. ❌ git switch branch1 -> make changes -> git switch branch2 This switch might cause overwrites in every unstaged file of the branch. ![]() Now, if we write something on ComponentOne.js file while being on branch1 and before committing or stashing the changes, we try to switch to another branch branch2, git will abort that and throw a warning, as they have the same file in both of the branches. Let's imagine we have a file named ComponentOne.js in both branch-1 and branch-2. Otherwise, if there are conflicting files in two branches (the same file is present in two different branches), all the unstaged changes will be lost. We must commit or stash the changes we made in the branch, before switching to another branch. And whatever commit we do, will be on this branch from now on unless we switch to another branch.Ĥ️⃣ □ Switching Branches with Unstaged Changes We have switched to the bugfix branch and now HEAD will point to the bugfix branch alone. To view all the branches of the current repo, write the following command: Let's say we switch to a branch named FeatureBranch1: ![]() So, HEAD is kind of like a bookmark in a book. Then we can switch back to the main branch or any other branch and HEAD will now point to that. If we change branch from master/ main to another, HEAD will now point to the latest commit of that branch instead. It points to a particular branch reference.īy default HEAD points to the latest commit on the main branch, but that can be moved around which changes the HEAD. Head is a pointer that refers to the currently active location in the repository we are accessing/viewing. Things to remember while working with branch: 1️⃣ HEAD Branchīranching makes it easier to work within self-contained contexts and to work in parallel. I'm also assuming you have some kind of idea why there is a requirement of merging branches. It's assumed you already know why it is important to use branches in git. If you are looking for a complete course on git and GitHub and don't mind videos, I would recommend this course by Colt Steele. But if you are looking for a full-fledged tutorial, this is probably not the place. You still might get a lot out of it if you are a beginner. I wrote this to be a reference or a short guide for the future. Before starting, I want to mention this is not a tutorial for git branch and merge. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |