Local Git Remotes

surprisetalk2 pts0 comments

local git remotes — alexander cobleigh / cblgh.org

Local git remotes

As part of working on cani I was also using a variety of git remotes. One of the remotes was<br>hosted on a server I have at home. Here&rsquo;s how I set that up.

Let&rsquo;s say the server has a project in a folder called cani. This folder has the code and a .git/ directory:

/home/user/projects/cani

We can use the above folder to clone a bare repository (can be used as a remote without causing weird conflicts):

cd /home/user/bares<br>git clone --bare /home/user/projects/cani<br># creates /home/user/bares/cani.git

To add this bare repository as a remote to push & pull from can look like a few different ways.<br>Here&rsquo;s the remote while on the same machine:

git remote add local /home/user/bares/cani.git

Here&rsquo;s how you can set up the remote when pushing from another machine:

git remote add local ssh://USER@MACHINE:/home/user/bares/cani.git

We can associate the branch main as the default branch for remote local:

git remote set-branches local main

Now we&rsquo;re ready to push to our local remote!

# without any config<br>git push ssh://USER@MACHINE:/home/user/bares/cani.git

# if remote configured with ssh://USER@ as above<br>git push local

Pulling from the configured remote:

# without default branch<br>git pull local main

# with default branch branch `main`<br>git pull local

For what it&rsquo;s worth, the ssh://USER@MACHINE syntax can be replaced with any ssh config you<br>might have set up locally.

Anyway! I really liked working with a local remote, especially when working with offsite<br>remotes with lower uptime. Setting up a local remote made it a much more relaxing to use a<br>remote that is maybe not always available. In my own case, the offsite remote is a small<br>community server that is getting massively hammered by big corporate scrapers. Now I have the<br>best of both: a local remote I can push to with no delay and an offsite copy hosted by a friend<br>in an online community. Notably, no big tech is involved!

remote local user cani home remotes

Related Articles