LinuxCommandLibrary

git-scp

Securely copy Git repositories over SSH

TLDR

Copy unstaged files to a specific remote

$ git scp [remote_name]
copy

Copy staged and unstaged files to a remote
$ git scp [remote_name] HEAD
copy

Copy files that has been changed in the last commit and any staged or unstaged files to a remote
$ git scp [remote_name] HEAD~1
copy

Copy specific files to a remote
$ git scp [remote_name] [path/to/file1 path/to/file2 ...]
copy

Copy a specific directory to a remote
$ git scp [remote_name] [path/to/directory]
copy

SYNOPSIS

git-scp [-C <dir>] [-v] <repo> <user@host:/path>

PARAMETERS

-C <dir>
    Change to <dir> before running, like git's -C.

-v
    Enable verbose output during the SCP transfer.

DESCRIPTION

git-scp is a convenient utility from the git-extras package that enables secure copying of Git repositories to remote servers using SCP. It smartly handles both bare and non-bare repositories by copying the essential .git directory contents to the destination, creating a functional bare repository remotely.

Unlike manual scp usage, which requires specifying exact paths and handling Git structure, git-scp automates this process. Provide the local repo path and remote destination in standard SCP format (e.g., user@host:/path/to/repo.git). It preserves Git objects, refs, and config files via recursive SCP transfer.

Ideal for quick repo deployment to servers for cloning by others, bypassing complex Git remote setups or push permissions. Supports working directory changes and verbose logging. Note: it's a file-level copy, not a Git protocol operation, so ensure SSH access and compatible Git versions.

CAVEATS

Part of git-extras, not core Git; install separately.
Requires SSH access to remote.
Destination path ideally ends in .git and should not exist to avoid issues.
Copies files only; run git fsck remotely if needed.

INSTALLATION

Ubuntu/Debian: sudo apt install git-extras
macOS (Homebrew): brew install git-extras
Fedora: sudo dnf install git-extras
GitHub: Clone https://github.com/tj/git-extras and make install.

EXAMPLE USAGE

git-scp myrepo.git user@example.com:/srv/git/myrepo.git
Copies local myrepo.git as bare repo to remote.

HISTORY

Created for git-extras by Linus Cederqvist around 2011. git-extras project gained popularity for extending Git with practical tools; git-scp standardized repo sharing via SCP in early releases and persists in modern versions (e.g., 6.0+).

SEE ALSO

scp(1), rsync(1), git-clone(1), git(1)

Copied to clipboard