Using git for version control it's in itself a great help, however, the tool becomes more useful when it has to be used to upload code or projects to a local server.
To start, you must verify that your server has git installed, then you must create an empty repository with the next command:
git --bare init <Repo name> # By convention, empty repos have the .git extension. # Example: git --bare init glowing-computing-machine.git
Once you've created the empty repo, you can access it and view a similar structure.
Now, for your repo to update automatically, you must add a hook... exacly, in the hooks folder, you'll find some by default but the one you'll use is called different: post-receive. Create the file and add the next line:
git --work-tree=<destination path> --git-dir=<origin path> checkout -f # The origin path will be the path where your empty repo will be placed # And destination path will be the path where your files will be inserted # By instance: git --work-tree=/home/hali/Documentos/Git/_site \ --git-dir=/home/hali/Documentos/Git/glowing-computing-machine.git \ checkout -f
Finally, add the permissions to execute the created file
chmod +x post-receive
Only you must review, that your destination directory is completely empty
Then, execute git clone
Ready!, we can upload content... but it becomes annoying to have to write our password every time we do pull or push, so with the help of ssh-copy-id command, we can add our public ssh key to list of accepted keys on the server
ssh-copy-id <server IP>
That's how we can upload code to our repo and it will be automatically copied in the folder that we choose.
Top comments (0)