Reputation: 3521
My question is really innocent. I've been reading up on git, and I already know the basics like pushing and pulling and creating branches and so on. My mentor told me that the proper way to work with git is to pull the resources, create a new local branch, transfer and edit that local branch and once you're done, go back to master branch and merge it with your local branch. Now my question is, what exactly happens behind the scene?
I mean, when git creates a local branch, does it create a copy of the master branch that you can edit? If it does, where are these copies located?
If by any chance I mess up on my local branch, how do I revert back the changes(let's say for example, I want to go back to the way it was when I pulled the master)? Is it just a simple matter of going back to master and deleting the local branch?
I suppose that the reason why people call it version control is because of the branches, which I think...Represents the version. Am I correct?
Why is the master called a branch? Shouldn't it be a trunk? okay that just a very dumb question, ignore #4... hahaha!
Answers to my innocent childlike questions shall be appreciated. <3 <3 <3
Upvotes: 3
Views: 150
Reputation: 301037
I mean, when git creates a local branch, does it create a copy of the master branch that you can edit? If it does, where are these copies located?
Branch is not a copy. A branch in Git is just a "pointer" to the latest commit. The commit object point to their parent(s) and that is how you get the entire "branch".
So as soon as you branch from master, you get one more pointer to the same commit. Nothing less, nothing more. Now both master and branch point to the same commit. As you keep committing in the branch now, the branch pointer keeps moving to point to it's branch specific commits.
If by any chance I mess up on my local branch, how do I revert back the changes(let's say for example, I want to go back to the way it was when I pulled the master)? Is it just a simple matter of going back to master and deleting the local branch?
If you don't like a branch, just delete it - git branch -d hotfix
Branches in Git are cheap, as, like I said, it is just a pointer to a commit which means it is a file which contains the 41 character SHA-1 checksum in .git\refs\heads\branchname
If you do not want to delete the branch, reset to a previous commit using something like git reset --hard HEAD~1
I suppose that the reason why people call it version control is because of the branches, which I think...Represents the version. Am I correct?
We call them version control because of each revisions or commits which is the unit of change. Branch is a collection of changes since a particular commit or branching point.\
PS: I am of course paraphrasing ProGit, so since you had commented that you had read it, I am not sure my answer will be of help.
Upvotes: 2