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 [OPTIONS] <SOURCE> <DESTINATION>

PARAMETERS

<SOURCE>
    The path to the source repository. This can be a local directory (e.g., . or /path/to/repo) or a remote path (e.g., user@host:/path/to/repo.git).

<DESTINATION>
    The path to the destination location. This can be a local directory or a remote path. The behavior (push/pull) depends on whether <SOURCE> or <DESTINATION> is remote.

--bare
    (Optional) When used, treats the source as a bare repository or creates a bare repository at the destination. A bare repository contains the Git history but no working tree.

--mirror
    (Optional) Similar to --bare, but sets up a mirror of the repository, including all references (branches, tags, remotes) exactly as they are in the source.

--tags
    (Optional) Transfers all tags from the source to the destination during the copy operation.

--all
    (Optional) Transfers all branches and tags from the source to the destination. This is often implied or part of --mirror functionality.

--dry-run
    (Optional) Performs a simulation of the transfer without actually copying any data. It shows what actions would be taken.

--verbose
    (Optional) Enables verbose output, showing the underlying scp and git commands executed by the script.

DESCRIPTION

git-scp is a non-standard Git helper command that facilitates the transfer of Git repositories or objects between local and remote hosts using the Secure Copy Protocol (SCP). It is particularly useful in environments where standard Git protocols (SSH, HTTP/S, Git protocol) are not configured, are restricted, or when a quick, direct copy is needed without setting up a full Git server.

Instead of relying on daemons like git-daemon or git-http-backend, git-scp leverages scp to copy necessary Git objects, references (refs), and packed files. This command is typically implemented as a shell script that wraps core git commands (such as git bundle, git push, or git fetch) and the scp utility for the actual data transfer.

It can be used to push changes from a local repository to a bare repository on a remote server, or to pull updates from a remote bare repository. While it simplifies the manual process of bundling and transferring repositories, it's important to note that git-scp is not part of the official Git distribution, and its exact functionality can vary depending on the specific script implementation.

CAVEATS

git-scp is not a standard, officially distributed Git command. Its availability, exact feature set, and behavior depend entirely on the specific third-party script implementation you are using.

It requires scp and ssh to be installed and properly configured on both the local and remote hosts involved in the transfer. This often means SSH keys need to be set up for passwordless access.

While data is transferred securely over SSH, the script itself is a wrapper. Its reliability and security depend on the quality of its implementation. For very large repositories, native Git protocols (like SSH or HTTP) are generally more efficient than git-scp, as it may involve bundling/unbundling steps.

EXAMPLES

Push a local repository to a remote bare repository:
git scp . user@remote.com:/srv/git/my-project.git

Clone a remote bare repository to a local directory:
git scp --bare user@remote.com:/srv/git/another-project.git ./local-clone

Perform a dry run to see what would be copied:
git scp --dry-run ~/my_repo user@remote.com:/tmp/test_repo.git

INSTALLATION

Since git-scp is a standalone script, its installation is straightforward:

1. Download the script: Obtain the git-scp script from a trusted source (e.g., a community repository or a personal gist).
2. Place it in PATH: Copy the script to a directory that is included in your system's PATH environment variable (e.g., /usr/local/bin/, ~/bin/).
3. Make it executable: Ensure the script has execute permissions: chmod +x /path/to/git-scp

After these steps, Git will automatically recognize and allow you to invoke the script as git scp, as Git looks for executable files named git-* in your PATH.

HISTORY

git-scp does not have a centralized or official development history like core Git commands. It emerged organically as a community-driven solution to specific challenges, particularly for users needing to transfer Git repositories when standard Git protocols were difficult or impossible to set up.

Many independent developers have created their own versions of git-scp scripts, often sharing them as gists or part of larger collections of Git helper utilities (e.g., git-extras). Its usage became prominent in scenarios involving strict firewall rules or limited server configurations where setting up git-daemon or git-http-backend was not feasible.

While not a primary Git workflow tool, it continues to serve as a niche, practical utility for specific deployment, backup, or ad-hoc repository transfer scenarios.

SEE ALSO

git(1), scp(1), ssh(1), git-bundle(1), git-push(1), git-fetch(1)

Copied to clipboard