Git – Where is the git working directory

gitmacos

Fellow coders, today is my first dive into git using Tower on the Mac – life's too short to mess with the command line 😉

I did read a few intros and tutorials but none addressed the question I'm writing about. I'm having some trouble understanding the working directory concept in git vs. SVN.

What I did:

  1. I created a local repo and pointed it to the folder where my project files are.
  2. Added and committed all the files in the folder.
  3. Edited a file. Showed up as modified.
  4. Added and committed the file.

These steps worked.

So far I have not been asked for the location of the working directory and I cannot checkout the master HEAD (the option is disabled). My question is: Is my original folder acting as the checkout working directory? When does the checkout command work? Does it only come to play when I have multiple branches?

Hope someone can clarify this before I go any further.

Best Solution

When switching from one source control system to another, one often finds that there are many terms in common, except that some "common" terms actually have different meanings in the two systems. And it becomes even more confusing because git's branching model is quite different from that of SVN. (Warning: my SVN is getting a little rusty, so feel free to correct any errors.)

Working directory has the same meaning: it is the directory where you checked out the repository (or the one where you created a local repo), and where the files you directly work with reside. However, what SVN calls checking out (namely, copying the contents of a remote repository and "linking" your repository to the remote one) is called cloning in git. In git, checking out means to switch to another branch or revision.

In SVN, branching works by "copying" the entire repository to another folder (on the server), and locally, you can checkout the branch (into another working directory, if you want to). So in a sense, a branch is a full repository on its own.

In git, there is only one repository, which contains the entire development history as an acyclic graph of revisions. A revision has one or two parents, and given a revision, any number of revisions may have it as a parent (so many revisions can branch out from one revision, and a revision may be a merge of two revision sequences). At any point in time, you may checkout a specific revision. This operation will make the working directory contents equal to what they were at the time of the specified revision (in other words, it will "replay" all revisions from the initial revision up to the specified one).

What is a branch in git, then? It is simply a label that is attached to a revision. If you check out a branch, you get the effect same effect as if you had directly checked out the branch' revision, but when you commit, the label will automatically move forward to the new revision.

Finally: In SVN, HEAD refers to the "main" branch; in git, it refers to the commit or branch that you have currently checked out.