{"id":212,"date":"2018-09-13T17:30:53","date_gmt":"2018-09-13T21:30:53","guid":{"rendered":"https:\/\/www.ectropyarts.com\/?p=212"},"modified":"2023-01-11T11:47:59","modified_gmt":"2023-01-11T16:47:59","slug":"use-git-with-just-a-shared-network-drive-no-git-server-required","status":"publish","type":"post","link":"https:\/\/www.ectropyarts.com\/use-git-with-just-a-shared-network-drive-no-git-server-required\/","title":{"rendered":"Use git with just a shared network drive. No git server required!"},"content":{"rendered":"
Want to use git for a small team of developers, but can’t (or don’t want to) use a git server? No problem! All you need is a shared network drive (like a dev server) that all of your developers can access. You’ll set up a repository for each developer, a central bare repository for them to push files to, and a git hook to auto-deploy files to a folder of your choice. This workflow works great for projects like websites and web applications.<\/p>\n
<\/p>\n
In the end we’ll expect to have a structure that looks something like this.<\/p>\n
\u251c\u2500\u2500 app\/\n\u2502 \u2514\u2500\u2500 index.html\n\u251c\u2500\u2500 app.git\/\n\u2502 \u251c\u2500\u2500 hooks\/\n\u2502 \u2502 \u2514\u2500\u2500 post-receive\n\u2502 \u251c\u2500\u2500 info\/\n\u2502 \u251c\u2500\u2500 objects\/\n\u2502 \u251c\u2500\u2500 refs\/\n\u2502 \u251c\u2500\u2500 config\n\u2502 \u251c\u2500\u2500 description\n\u2502 \u251c\u2500\u2500 HEAD\n\u2502 \u2514\u2500\u2500 index\n\u251c\u2500\u2500 app-developerOne\n\u2502 \u251c\u2500\u2500 .git\/\n\u2502 \u2514\u2500\u2500 index.html\n\u2514\u2500\u2500 app-developerTwo\/\n \u251c\u2500\u2500 .git\/\n \u2514\u2500\u2500 index.html\n<\/pre>\nLet’s begin!<\/p>\n
\n
- Ensure you have git<\/a> installed.<\/li>\n
- Open up git bash. We’ll be using the bash command line for most of this guide.<\/li>\n
- Set up a bare repository. Conventionally, the folder that is used for your bare repo should end in
.git<\/code>. For this example, we’ll pretend the name of our application is
app<\/code> and call the bare repo’s folder
app.git<\/code> accordingly.
\n(The next few commands are based on this stack overflow answer.<\/a>)<\/span><\/p>\nmkdir app.git\ncd app.git\ngit init --bare<\/pre>\nWhy a bare repo?<\/a> A bare repo acts sort of like your team’s “GitHub”. Developers pull latest changes from this repo into their personal repositories, then later push their changes back into this repo. No one will ever directly edit the files in the bare repo. In fact, they can’t. Bare repos don’t even show the source-controlled files–they have no working or checked out copy of these files. You can read more about bare git repos here<\/a>.<\/li>\n
- Next, back out of the
app.git<\/code> folder, then set up a repo for your first developer. Normally I’d name the developer repos after my developers, but for this example I’ll just call our first developer “developerOne”\n
cd ..\nmkdir app-developerOne\ncd app-developerOne\ngit init<\/pre>\n<\/li>\n- Add any of your app’s existing files to this newly created repo (the
app-developerOne<\/code> folder). In my example I simply added an
index.html<\/code> file.<\/li>\n
- Stage all files (can be done on command line or with GUI.)\n
git add .<\/pre>\n<\/li>\n- Commit all files (can be done on command line or with GUI.)\n
git commit -m \"Initial commit.\"<\/pre>\n<\/li>\n- Add the
app.git<\/code> bare repo as this repo’s “origin”.\n
git remote add origin ..\/app.git<\/pre>\n<\/li>\n- Before pushing for the first time, let’s set up a git hook to automatically copy pushed changes to a folder. Go ahead and navigate to the hooks folder, and use
touch<\/code> to create an empty file named
post-receive<\/code>. Note, the
post-receive<\/code> file won’t have any extension.\n
cd ..\ncd app.git\/hooks\ntouch post-receive<\/pre>\n<\/li>\n- Edit the
post-receive<\/code> script to add the following code. You could use a command line editor like nano or vim, or simply open the file in a text editor such as Notepad++<\/a> or Atom<\/a>.
\nYou must change..\/app<\/code> (near DEPLOYDIR) to be the actual name of the folder you wish to push to. You shouldn’t have to change anything else.
\n(This post-receive script was based on this one<\/a>.)<\/span><\/p>\n#!\/bin\/sh\necho \"Executing post-receive script. (Located in the --bare repo's hooks folder.)\"\n\n# Instructions:\n# Put this file into your .git\/hooks folder and set as executable \n\n#- for Windows (attrib +x pre-commit)\n#- for ubuntu (chmod +x pre-commit)\n\nDEPLOYDIR=..\/app # The place to deploy to.\nBRANCH=\"master\"\n\nread oldrev newrev ref\n\n# Only auto-deploy (checkout) the $BRANCH specified above.\nif [[ $ref = refs\/heads\/$BRANCH ]];\nthen\n echo \"Branch $ref received. Deploying ${BRANCH} branch to \\\"$DEPLOYDIR\\\" folder.\"\n git --work-tree=$DEPLOYDIR checkout -f\n echo \"Done.\"\nelse\n echo \"Branch $ref received. Doing nothing: only the ${BRANCH} branch may be auto-deployed to the \\\"$DEPLOYDIR\\\" folder.\"\nfi\n<\/pre>\n