notesI'm doing this on OSX terminal, so will probably work on OSX/Linux, less likely on command prompt. Use CMDER to be happy...
First we create an empty folder to house our working directory
cd gitdemoThen create the .git folder that stores our copy of the repository
Now we start creating some git files, the HEAD file contains a string that says what the HEAD currently points to, HEAD is a pointer to the currently checked out location.
echo "ref: refs/heads/master" > HEAD
Then we create the objects folder
Then we create the refs folder with the heads folder inside of it
You can now use this as a working git repository!
Make sure you change back to the gitdemo directory
echo "console.log('hello')" > index.js
git add -A
git commit -m "initial commit"
If you've done everything correctly this should work!
Now if you look inside of the .git folder you can see that git has started adding more things to the objects folder, as well it has created ./.git/refs/heads/master
This should output a commit hash, so we see that this basically says master is on this commit.
I wonder if we can create a branch by just copying this file...
cat ./.git/refs/heads/master ./.git/refs/heads/mybranch
But then could we check this out by changing the HEAD file, I mean it won't update the working directory but as they are both pointing at the same commit this should be fine?
echo "ref: refs/heads/mybranch" > HEAD
Hopefully this starts to give you an understanding of how gits refs/branches and HEAD work on disk.