All of them simultaneously editing the same source code files. Let’s dive a little deeper into the details! Why are branches so useful?īranching’s value becomes clear if you think about your workflow without them: imagine that a team of 10 or 20 developers all work in the same “folder,” so to speak. For example, they don’t waste disk space (which a simple file system copy would do) and they are much more capable when it comes to collaborating with other developers in the same project.
Of course, they are much more clever than our simple “copy folder” strategy. But there’s an easy way to mitigate these risks: you could simply duplicate the whole project folder! In this copy, you could then make any changes you like, without worrying about breaking something.īranches in Git have the exact same effect and purpose: they provide developers with separate workspaces for their code. In such a situation you would have to be very careful when making changes-because you couldn’t easily undo them and you would risk breaking the current, working version. Just for a moment, let’s pretend that version control and especially its concept of “branches” didn’t exist. when developing a new feature or fixing a problem) will most likely involve a couple of those files. Put simply, a code base is a collection of files. We’ll be looking at the concept of branches in Git from a high-level perspective-with the ultimate goal of better understanding what they are and how they should be used so that you and your team can get the most benefit out of them.
Since your changes were never committed, you'd lose them. If you really want to discard the local changes, you have to force the checkout with -f. That is why your last status still show your local changes, although you are on master. git did change the HEAD, but did not overwrite your local files. , which means that your working files are not clean. The result of your checkout master is: M testing Upon changing branch, git does not overwrite your local changes. Since the changes are only local, git does not want you to lose them too easily. Edit to explain the result of checkout master -Īre you confused because checkout master does not discard your changes? It just creates the branch from the current HEAD and sets the HEAD there. git checkout -b new_branch_nameĭoes not touch your local changes. Saved working directory and index state WIP on master: 4402b8c testingĭropped (db1b9a3391a82d86c9fdd26dab095ba9b820e35b)ĭo you know if there is any way of accomplishing this?
No changes added to commit (use "git add" and/or "git commit -a") " to discard changes in working directory) Nothing to commit (working directory clean) I supposed git stash & git stash branch new_branch would simply accomplish that but this is what I get: ~/test $ git status
This always happens to me and I have no idea how to switch to another branch and take all these uncommited changes with me leaving the master branch clean. After a few minutes I realize it was not so simple and it should have been better to work into a new branch. Context: I'm working on master adding a simple feature.