DEV Community

Janak Shrestha
Janak Shrestha

Posted on

Clone Git Repository on Storage Server

The DevOps team established a new Git repository last week, which remains unused at present. However, the Nautilus application development team now requires a copy of this repository on the Storage Server in the Stratos DC. Follow the provided details to clone the repository:

The repository to be cloned is located at /opt/cluster.git

Clone this Git repository to the /usr/src/kodekloudrepos directory. Perform this task using the natasha user, and ensure that no modifications are made to the repository or existing directories, such as changing permissions or making unauthorized alterations.


Step 1: SSH Into the Storage Server

From the jump host, connect to the Storage Server as natasha:

ssh natasha@ststor01        # password: Bl@kW
Enter fullscreen mode Exit fullscreen mode

If the hostname doesn't resolve, use the server's IP address instead:

ssh natasha@10.244.49.64    # password: Bl@kW
Enter fullscreen mode Exit fullscreen mode

Once connected, you'll see a prompt like:

[natasha@ststor01 ~]$
Enter fullscreen mode Exit fullscreen mode

Step 2: Navigate to the Target Directory

Move into the directory where the repository should be cloned:

cd /usr/src/kodekloudrepos
Enter fullscreen mode Exit fullscreen mode

Verify you're in the right place:

pwd
Enter fullscreen mode Exit fullscreen mode

Expected output:

/usr/src/kodekloudrepos
Enter fullscreen mode Exit fullscreen mode

Step 3: Clone the Repository

Clone the bare repository from /opt/cluster.git into the current directory:

git clone /opt/cluster.git
Enter fullscreen mode Exit fullscreen mode

Expected output:

Cloning into 'cluster'...
warning: You appear to have cloned an empty repository.
done.
Enter fullscreen mode Exit fullscreen mode

ℹ️ Note: The "empty repository" warning is completely normal. It simply means the repository has no commits yet — the clone itself was successful.

This creates a new folder named cluster inside /usr/src/kodekloudrepos.


Step 4: Verify the Clone

Move into the cloned directory:

cd cluster
Enter fullscreen mode Exit fullscreen mode

Check the remote configuration:

git remote -v
Enter fullscreen mode Exit fullscreen mode

Expected output:

origin  /opt/cluster.git (fetch)
origin  /opt/cluster.git (push)
Enter fullscreen mode Exit fullscreen mode

Confirm the directory contents:

ls -la
Enter fullscreen mode Exit fullscreen mode

You'll see the .git/ directory — this is the working copy of the repository.


Step 5: Confirm Ownership

Ensure everything is owned by natasha, since the clone was performed under that user:

ls -la /usr/src/kodekloudrepos
Enter fullscreen mode Exit fullscreen mode

Expected output:

drwxr-xr-x 3 natasha natasha 4096 Oct  6 05:18 cluster
Enter fullscreen mode Exit fullscreen mode

And inside the cloned folder:

ls -la /usr/src/kodekloudrepos/cluster
Enter fullscreen mode Exit fullscreen mode

Expected output:

drwxr-xr-x 3 natasha natasha 4096 Oct  6 05:18 .
drwxr-xr-x 3 natasha natasha 4096 Oct  6 05:18 ..
drwxr-xr-x 6 natasha natasha 4096 Oct  6 05:18 .git
Enter fullscreen mode Exit fullscreen mode

Every entry should show natasha natasha — confirming the clone is correctly owned. ✅


Step 6 (Optional): Document the Clone with a Heredoc

If you want to leave a log or note file describing the clone, use a heredoc to write it without opening an editor:

cat <<'EOF' > clone-info.txt
Repository cloned: /opt/cluster.git
Destination:      /usr/src/kodekloudrepos/cluster
Cloned by user:   natasha
Date:             $(date)
Notes:
  - Bare source repo, non-bare working copy.
  - No permissions or ownership were modified.
EOF
Enter fullscreen mode Exit fullscreen mode

Verify:

cat clone-info.txt
Enter fullscreen mode Exit fullscreen mode

⚠️ Only create this file if your task allows adding new files. If the instructions say "no modifications," skip this step.


Recap: What We Did

Step Action
1 SSH'd into the Storage Server as natasha
2 Navigated to /usr/src/kodekloudrepos
3 Cloned /opt/cluster.git with git clone
4 Verified the remote with git remote -v
5 Confirmed ownership with ls -la
6 (Optional) Documented the clone using a heredoc

Common Pitfalls to Avoid

Pitfall Why It's a Problem
Using git init instead of git clone Creates a brand-new empty repo, not a copy of the source
Cloning as the wrong user Files will be owned by that user, breaking team access
Adding sudo unnecessarily Files become root-owned, causing permission issues
Worrying about "empty repository" warning This is expected for repos without commits
Modifying permissions with chmod/chown Often prohibited; not needed when cloning as the right user

Key Takeaways

  1. Clone as the correct user — ownership follows whoever runs the command.
  2. git clone <path> works with local paths, not just URLs.
  3. The "empty repository" warning is not an error.
  4. Always verify with git remote -v and ls -la.
  5. Use heredocs (<<'EOF') to write files cleanly without opening an editor.
  6. Avoid unnecessary sudo — it changes file ownership.

Top comments (0)