67db91dd-3847-4b3f-9b8d-392.../docs/03-init-and-clone.md

984 B

git init & clone

Goal

Create a new repository from scratch and clone a repository.

Prepare a Workspace

mkdir -p ~/lab-git-essentials
cd ~/lab-git-essentials
pwd

Initialize a New Repository

mkdir my-first-repo
cd my-first-repo
git init
git status

Add a First File

echo "# My First Repo" > README.md
git status

Alternative: Clone an Existing Repository

If you have internet and a Git hosting account (e.g., GitHub), you can clone:

# Example: public repo (replace with one you prefer)
cd ~/lab-git-essentials
git clone https://github.com/git/git --depth 1 git-source
ls git-source

Offline Option: Clone a Local Path

You can clone from a local repo path via file protocol:

cd ~/lab-git-essentials
git clone file://$HOME/lab-git-essentials/my-first-repo my-first-repo-clone
ls my-first-repo-clone

Outcome

You created a new Git repository and learned how to clone both remote and local repositories.