DEV Community

Halí
Halí

Posted on • Edited on • Originally published at halivert.github.io

1

Git in local server

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
Enter fullscreen mode Exit fullscreen mode

Once you've created the empty repo, you can access it and view a similar structure.

bare-repo

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
Enter fullscreen mode Exit fullscreen mode

Finally, add the permissions to execute the created file

chmod +x post-receive
Enter fullscreen mode Exit fullscreen mode

Only you must review, that your destination directory is completely empty

ls site

Then, execute git clone

ls-glowing

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>
Enter fullscreen mode Exit fullscreen mode

ssh-copy-id

That's how we can upload code to our repo and it will be automatically copied in the folder that we choose.

commit-inicial
ls-site-commit

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay