DEV Community

Justin
Justin

Posted on

πŸ”§ Using git with a local ssh server

Let's say you're ripping on a project and maybe have two computers at home or you don't feel like sharing the project you're working on to github/gitlab just yet.

You can use git + ssh to keep those two projects in sync and its super easy.

This is also a good way to work projects across computers without having to rsync or scp files.

Assuming you have a git project and a ssh connection already, you are pretty much all set. Just follow these instructions:

# on the remote server copy down what git you do have _or_
# create a new folder/git to sync it to
ssh user@host "git init --bare /mnt/foo/bar/my-project.git"

# then add that remote server
git remote add origin ssh://user@host/mnt/foo/bar/my-project.git

# and finally, push to it!
git push origin master
Enter fullscreen mode Exit fullscreen mode

Keep in mind, if you already have an origin, you can rename that to something like "local-server", then you have a "git push local-server" for local testing or "git push origin" for when its time to really deploy.

Happy coding!

Top comments (0)