October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Clone a Git Repository on a Linux Server

Use git clone on a Linux server with the right branch, depth and authentication settings. This guide covers public and private repositories, SSH deploy keys, shallow history, verification and troubleshooting.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

On a Linux server, the basic operation is git clone <url>. Git creates a new working directory named after the repository, downloads its objects, and checks out the repository’s default branch. Add --branch when you need a particular branch, use --depth 1 for a fast deployment clone with only recent history, and use a repository-specific, read-only SSH deploy key for a private repository.

What cloning does on a server

git clone creates a new local copy from a remote repository. Unless you provide a destination directory, Git derives the new directory name from the repository name in the URL. The resulting directory is a normal working tree containing a hidden .git directory, so you can run commands such as git status, git log, and git fetch inside it.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In a non-bare clone, the branch selected by --branch becomes the branch to which HEAD points and is checked out into the working tree. Without that option, Git uses the remote repository’s default branch. A clone is not a one-time archive: it retains the remote named origin, allowing later fetches and updates.

Before you run the command

  • Git must be available on the server. Confirm with git --version. The exact package-install command depends on the Linux distribution; this guide does not assume Debian, Ubuntu, RHEL, or another specific family.
  • Choose a location writable by the account that will run Git. Deployment users commonly work in an application directory under their home directory or in a service-owned release path. Do not clone as a different account and expect the deployment account to update the files later.
  • Have the complete remote URL. HTTPS and SSH URLs use different credential mechanisms. For a public repository, either may work; a private repository requires credentials that the server can use non-interactively.
  • Check available disk space. A full clone includes repository history and can be substantially larger than the checked-out files. A shallow clone can reduce the initial transfer when history is not needed.
  • Decide whether the server needs history. Runtime deployments and many CI jobs only need the files at one revision. Builds that calculate changelogs, inspect tags, run history-based versioning, or create patches need more history.

Clone a public repository

Use the default branch

Change to the parent directory and run:

cd /path/where/the/project-should-live
git clone <url>

Replace <url> with the repository’s HTTPS or SSH URL. Git creates a directory based on the repository name. Enter it and verify the working tree:

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.
cd repository-name
git status
git remote -v

git status should report the checked-out branch and a clean tree immediately after a successful clone. git remote -v shows the fetch and push URLs recorded for origin.

Choose the destination directory explicitly

Pass a second argument when the directory name must differ from the repository name:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
git clone <url> /srv/apps/my-game

The destination must not already contain an unrelated working tree. If the directory exists and is not empty, Git normally refuses to clone into it; choose an empty path or a new release directory rather than deleting files blindly.

Clone a specific branch

Use --branch (or its short form, -b) to select the branch at clone time:

git clone --branch staging <url>

For a non-bare repository, this both points HEAD at staging and checks that branch out. The command still downloads the repository data needed by the clone unless you also limit the history or branch scope.

If the branch name contains characters that your shell treats specially, quote the argument:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
git clone --branch 'release/2.4' <url>

A misspelled or nonexistent branch causes the clone to fail rather than silently selecting another branch. Confirm the name in the remote repository before putting the command in an automated deployment script.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Use a single-branch shallow clone for deployments

Latest commit only

When the server only needs the current files from one branch, use:

git clone --depth 1 --branch main --single-branch <url>

--depth 1 truncates history to one commit. The explicit --single-branch limits the clone to the history leading to the tip of main. This is useful for deploy and CI work where old commits, unrelated branches, and most repository metadata are unnecessary.

The result is a shallow repository. Commands that require ancestors outside the downloaded boundary can report incomplete history, and tools that expect every tag or commit may not work as they do in a full clone. Treat the clone as an intentionally limited checkout, not as a complete backup.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a larger depth

Set another positive number when a build needs a small amount of recent history:

git clone --depth 20 --branch main --single-branch <url>

The number is a commit count, not a number of days or megabytes. The appropriate value depends on the task: a deployment that only reads files can use one commit, while a changelog step may need enough commits to cover the release range.

Using --depth implies single-branch behavior unless you explicitly add --no-single-branch. Add that override only when a shallow clone must include history from more than the selected branch; it can increase the transfer and storage cost.

Deepen a shallow clone later

You do not have to discard a shallow checkout to obtain more history. From inside the clone, fetch additional commits:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)
cd /path/to/repository
git fetch --depth 20 origin main

This requests a history reaching a depth of 20 for main. Git’s fetch options also support deepening relative to the current shallow boundary; use the fetch documentation for the exact deepening or shortening mode required by your workflow. After fetching, inspect the available history with git log before relying on it in a build.

Clone a private repository with an SSH deploy key

Why a deploy key fits a single repository

A deploy key is an SSH key pair installed on the server and authorized for one repository. On GitHub, deploy keys are read-only by default. Write access is an explicit option, and a key is scoped to that one repository rather than to every repository belonging to a user account.

For a server that only pulls source code, keep the key read-only. A 2025 report from Read the Docs described deploy keys with write access being disabled after a security risk involving SSH-agent access. A write-capable key also turns a compromised server into a potential source of unauthorized repository changes.

Generate the key on the server

Log in as the account that will perform the clone and create the key pair there:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ssh-keygen -t rsa -f ~/.ssh/repo_deploy

GitHub’s documented example uses RSA. Ed25519 is widely used in modern SSH deployments, but the cited example does not establish it as the required choice; verify the current host guidance before standardizing on another key type. The command creates a private key at ~/.ssh/repo_deploy and a public key at ~/.ssh/repo_deploy.pub.

Keep the private key on the server and never paste it into repository settings, tickets, logs, or deployment output. Display or copy only the public-key file when authorizing the repository:

cat ~/.ssh/repo_deploy.pub

Authorize it in the repository settings

  1. Open the private repository’s settings.
  2. Choose Deploy keys.
  3. Add the complete contents of repo_deploy.pub.
  4. Leave Allow write access unchecked for a pull-only server.

Each deploy key works for one repository. If the same server must read several private repositories, do not assume one repository’s deploy key automatically grants access to the others. GitHub recommends considering a GitHub App with scoped, short-lived tokens when access to multiple repositories is required. That model can reduce the exposure of long-lived private keys, but its setup is outside this clone procedure.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Tell SSH which key to use

Create or edit ~/.ssh/config for the deployment account:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Host github-repo-deploy
    HostName github.com
    User git
    IdentityFile ~/.ssh/repo_deploy
    IdentitiesOnly yes

The alias lets you select this key without changing the host-wide SSH defaults. IdentitiesOnly yes tells SSH to use the identity specified for this host entry instead of trying unrelated keys from an agent. Protect the configuration and private key with the account’s normal SSH file permissions, and ensure the deployment process runs as the same account whose home directory contains these files.

Test authentication before cloning:

ssh -T [email protected]

A successful test confirms that SSH can reach the host and present an accepted identity. The test does not clone a repository and does not prove that the key has access to every repository; repository authorization is still checked during git clone.

Clone through the SSH alias

Use the alias from the configuration in the repository URL:

git clone git@github-repo-deploy:OWNER/REPOSITORY.git

Replace OWNER/REPOSITORY.git with the path for the authorized repository. You can combine the alias with branch and depth options:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
git clone --depth 1 --branch main --single-branch 
  git@github-repo-deploy:OWNER/REPOSITORY.git 
  /srv/apps/my-game

This pattern keeps the private key selection in SSH configuration while making the Git command suitable for a deployment script.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

HTTPS versus SSH on a server

The choice is primarily about how the server proves its identity and how much repository access that credential carries.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.
Property HTTPS clone SSH deploy-key clone
Credential form An HTTPS credential supplied through the host’s supported authentication method A private SSH key paired with a public key authorized in repository settings
Typical scope Depends on the token or account mechanism used One repository per deploy key
Server storage Requires a safe method for supplying and rotating the HTTPS credential Private key remains on the server; it is often unprotected by a passphrase for unattended jobs
Write permission Determined by the HTTPS credential’s scopes Read-only by default; write access must be explicitly enabled
Multiple repositories Can be practical with a carefully scoped token, depending on the host Separate keys are needed for separately authorized repositories, or use a host-supported app/token model

Neither transport makes a compromised server safe. A long-lived, passphrase-less deploy key is convenient for unattended pulls but remains usable until it is removed from the repository or replaced. Keep the key read-only, restrict the server account, and remove the key when the machine or deployment is retired.

Verify the clone before deploying files

  1. Check the directory: run pwd and git rev-parse --show-toplevel to confirm that the process is operating in the intended checkout.
  2. Check the selected branch: run git branch --show-current. This catches a destination or branch mistake before files are copied into a service directory.
  3. Check the remote: run git remote -v and confirm that the URL points to the expected host and repository.
  4. Check the worktree: run git status. A newly cloned tree should not contain edits created by an earlier deployment.
  5. Check shallow status when relevant: if the clone used --depth, treat history-dependent build steps as unverified until you confirm that the required commits or tags are present.

Only after these checks should an automation script link the checkout into a running service, build artifacts from it, or replace an existing release.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common failures and fixes

git: command not found

Git is not installed or is not on the service account’s PATH. Install Git using the procedure for the server’s distribution, then start a new session or use the fully qualified binary path if your service environment has a restricted path.

Permission denied while creating the destination

The current account cannot write to the parent directory. Choose a directory owned or writable by that account, or correct ownership and permissions according to your server’s deployment policy. Avoid running the clone as root merely to bypass a permissions error; that commonly leaves files that the application account cannot update.

SSH authentication fails

  • Confirm that the public key copied into Deploy keys is the contents of the matching .pub file, not the private key.
  • Run ssh -T [email protected] as the same account that will run Git.
  • Check that the SSH configuration’s IdentityFile path is correct and that the alias used in the Git URL exactly matches the Host entry.
  • Make sure the key was added to the intended repository and that write access was not enabled unnecessarily.

The repository or branch cannot be found

Check spelling, capitalization, owner, and repository visibility. A private repository can return an access-related error that resembles a missing repository when the key is not authorized. For a branch error, verify the branch name and repeat the clone with the correct value after removing the failed destination directory.

The clone is unexpectedly large or slow

A full clone downloads history that a deployment may never use. Select the required branch and use an appropriate --depth value. If a later build fails because it needs older commits, deepen the existing clone with git fetch --depth rather than starting over.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A build says history or tags are missing

That is an expected limitation of a shallow clone. Increase the depth, fetch the required branch history, or use a full clone for that job. Do not silently treat a shallow checkout as equivalent to a complete repository.

Operational checklist

  • Run Git as the intended non-root deployment account.
  • Use --branch when the default branch is not the release branch.
  • Use --depth only when the build does not require complete history.
  • For a private repository, generate the SSH key on the server and authorize its public half for that repository.
  • Keep deploy keys read-only unless a documented operation genuinely requires writes.
  • Use an SSH Host entry and IdentitiesOnly yes when the server has several identities.
  • Test SSH authentication before embedding the clone command in automation.
  • Verify branch, remote, path, and worktree status before activating the checkout.
  • Remove or rotate the deploy key when the server is decommissioned or the deployment design changes.

Command reference

Goal Command
Clone the default branch git clone <url>
Clone and check out one branch git clone --branch <branch> <url>
One-commit deployment clone git clone --depth 1 --branch main --single-branch <url>
Shallow clone with 20 commits git clone --depth 20 --branch main --single-branch <url>
Deepen an existing clone git fetch --depth 20 origin main
Generate an RSA deploy-key pair ssh-keygen -t rsa -f ~/.ssh/repo_deploy
Test SSH authentication ssh -T [email protected]
Clone with a configured SSH alias git clone git@github-repo-deploy:OWNER/REPOSITORY.git

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.