Remote GIT Bare Repo Setup
In CLI
-
Create a Directory for Git Repositories
Create a directory to hold your Git repositories:
mkdir -p ~/git-server/repos
-
Initialize a Bare Git Repository
Navigate to the repository directory and initialize a bare repository:
cd ~/git-server/repos git init --bare test-repo.git
With JGit in kotlin:
In Kotlin
package com.thorg.core.git
import org.eclipse.jgit.api.Git
import java.io.File
// # Clone repo:
// cd "$HOME" && git clone "ssh://${USER:?}@localhost:22/Users/${USER:?}/git-server/repos/test-repo.git"
//
// # Wipe out previous repo:
// rm -rf "$HOME/git-server/repos/test-repo.git"
fun main(args: Array<String>) {
val repoDir = File(
System.getProperty("user.home") + "/git-server/repos/test-repo.git"
)
// Create the bare repository.
//
// This calls succeeds and appears to be a no-op if the repo already exists.
Git.init()
.setBare(true)
.setDirectory(repoDir).call()
.use { git ->
System.out.println("Git repository at " + repoDir.getAbsolutePath())
}
}
Backlinks