From daa6640c1e62447ddabe4bc836088b89c594de59 Mon Sep 17 00:00:00 2001 From: labzy-handson Date: Sat, 20 Sep 2025 11:26:37 +0530 Subject: [PATCH] update --- docs/01-overview.md | 24 ++++++++++++ docs/02-install-and-setup.md | 44 +++++++++++++++++++++ docs/03-init-and-clone.md | 45 +++++++++++++++++++++ docs/04-add-commit-status.md | 38 ++++++++++++++++++ docs/05-branch-checkout-merge.md | 50 ++++++++++++++++++++++++ docs/06-pull-push-diff.md | 67 ++++++++++++++++++++++++++++++++ docs/07-view-history.md | 36 +++++++++++++++++ docs/08-undoing-things.md | 51 ++++++++++++++++++++++++ docs/09-tagging.md | 36 +++++++++++++++++ docs/README.md | 16 ++++++++ lab.yaml | 66 +++++++++++++++++++++++-------- 11 files changed, 457 insertions(+), 16 deletions(-) create mode 100644 docs/01-overview.md create mode 100644 docs/02-install-and-setup.md create mode 100644 docs/03-init-and-clone.md create mode 100644 docs/04-add-commit-status.md create mode 100644 docs/05-branch-checkout-merge.md create mode 100644 docs/06-pull-push-diff.md create mode 100644 docs/07-view-history.md create mode 100644 docs/08-undoing-things.md create mode 100644 docs/09-tagging.md create mode 100644 docs/README.md diff --git a/docs/01-overview.md b/docs/01-overview.md new file mode 100644 index 0000000..bcd759e --- /dev/null +++ b/docs/01-overview.md @@ -0,0 +1,24 @@ +# A Short History of Git & What is Git? + +## Goal +Understand why Git was created and what problems it solves. + +## Key Points +- Git was created by Linus Torvalds in 2005 for Linux kernel development. +- Core objectives: speed, data integrity, distributed workflows. +- Git stores content as snapshots (not diffs), referenced by hashes (SHA-1/SHA-256 in future). +- Distributed: every clone is a full repository with complete history. +- Common terms: repository (repo), commit, branch, tag, remote, working tree, index (staging area). + +## What You Will Use +- Terminal on Ubuntu 24.04 + +## Check Your Shell and Basic Tools +```bash +whoami +uname -a +which git || echo "git not installed yet" +``` + +## Outcome +You should be able to explain what Git is, why it exists, and the difference between working tree, staging area, and repository. diff --git a/docs/02-install-and-setup.md b/docs/02-install-and-setup.md new file mode 100644 index 0000000..a6ad724 --- /dev/null +++ b/docs/02-install-and-setup.md @@ -0,0 +1,44 @@ +# Installing Git & First-Time Git Setup + +## Goal +Install Git on Ubuntu 24.04 and configure your identity and defaults. + +## Install Git (Ubuntu 24.04) +```bash +sudo apt update +sudo apt install -y git +git --version +``` + +## Configure Identity (Required) +```bash +git config --global user.name "Your Name" +git config --global user.email "you@example.com" +git config --global --list +``` + +## Recommended Defaults +```bash +# Default branch name for new repos +git config --global init.defaultBranch main + +# Safer line endings for cross-platform projects +git config --global core.autocrlf input + +# Colorized output +git config --global color.ui auto + +# Preferred editor (choose one you use) +git config --global core.editor nano +# git config --global core.editor "code --wait" +# git config --global core.editor vim +``` + +## Verify Configuration +```bash +git config --global --list +cat ~/.gitconfig +``` + +## Outcome +Git is installed and your global identity and defaults are set. diff --git a/docs/03-init-and-clone.md b/docs/03-init-and-clone.md new file mode 100644 index 0000000..8863ff0 --- /dev/null +++ b/docs/03-init-and-clone.md @@ -0,0 +1,45 @@ +# git init & clone + +## Goal +Create a new repository from scratch and clone a repository. + +## Prepare a Workspace +```bash +mkdir -p ~/lab-git-essentials +cd ~/lab-git-essentials +pwd +``` + +## Initialize a New Repository +```bash +mkdir my-first-repo +cd my-first-repo +git init +git status +``` + +## Add a First File +```bash +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: +```bash +# 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: +```bash +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. diff --git a/docs/04-add-commit-status.md b/docs/04-add-commit-status.md new file mode 100644 index 0000000..4daec52 --- /dev/null +++ b/docs/04-add-commit-status.md @@ -0,0 +1,38 @@ +# git add, commit & status + +## Goal +Learn to stage changes, commit them, and inspect repository status. + +## Start with Untracked Changes +```bash +cd ~/lab-git-essentials/my-first-repo +echo "Some notes" > notes.txt +git status +``` + +## Stage Files +```bash +git add README.md notes.txt +git status +``` + +## Commit with a Message +```bash +git commit -m "Add README and notes" +git status +``` + +## Make and Review Further Changes +```bash +echo "Another line" >> notes.txt +git status +git add -p notes.txt # interactively stage hunks (optional) +git commit -m "Update notes with another line" +``` + +## Good Commit Messages +- Subject line in imperative mood (<= 50 chars) +- Optional body explaining the why (wrap ~72 columns) + +## Outcome +You can stage, commit, and check status confidently. diff --git a/docs/05-branch-checkout-merge.md b/docs/05-branch-checkout-merge.md new file mode 100644 index 0000000..7076832 --- /dev/null +++ b/docs/05-branch-checkout-merge.md @@ -0,0 +1,50 @@ +# git branch, checkout & merge + +## Goal +Create branches, switch between them, and merge changes. + +## Create and List Branches +```bash +cd ~/lab-git-essentials/my-first-repo +git branch +git checkout -b feature/intro +git branch +``` + +## Add Work on the Feature Branch +```bash +echo "Feature text" >> README.md +git add README.md +git commit -m "Add feature text to README" +``` + +## Switch Back to Main and Merge +```bash +git checkout -b main 2>/dev/null || true +git checkout main +git merge feature/intro +``` + +## Create a Merge Conflict (Optional, for practice) +```bash +# On main, change the same line differently +sed -i '1s/.*/# My First Repo (main)/' README.md +git add README.md +git commit -m "Tweak README title on main" + +# On feature branch, make a conflicting change +git checkout feature/intro +sed -i '1s/.*/# My First Repo (feature)/' README.md +git add README.md +git commit -m "Tweak README title on feature" + +# Merge and resolve +git checkout main +git merge feature/intro +# Open README.md, resolve conflict markers <<<<<<<, =======, >>>>>>> +git add README.md +git commit # finalizes the merge +``` + +## Outcome +You can branch, switch branches with `git checkout`, and merge changes, including resolving conflicts. diff --git a/docs/06-pull-push-diff.md b/docs/06-pull-push-diff.md new file mode 100644 index 0000000..48a6b34 --- /dev/null +++ b/docs/06-pull-push-diff.md @@ -0,0 +1,67 @@ +# git pull & push & diff + +## Goal +Work with a remote, push and pull changes, and compare differences. + +## Set Up a Local "Remote" (Offline-Friendly) +We'll simulate a remote using a bare repository. +```bash +cd ~/lab-git-essentials +git init --bare remote.git +``` + +## Connect Your Repo to the Remote +```bash +cd ~/lab-git-essentials/my-first-repo +git remote add origin file://$HOME/lab-git-essentials/remote.git +git remote -v +``` + +## Push Your Main Branch +```bash +git checkout main +git push -u origin main +``` + +## Simulate a Collaborator and Pull +Create a second local clone, make a change, push it, then pull it back. +```bash +cd ~/lab-git-essentials +git clone file://$HOME/lab-git-essentials/remote.git collaborator +cd collaborator +echo "Edit from collaborator" >> collab.txt +git add collab.txt +git commit -m "Collaborator adds a file" +git push origin HEAD:main + +# Back in your original repo, pull the change +cd ~/lab-git-essentials/my-first-repo +git pull +ls +``` + +## View Differences +```bash +# Compare working tree vs last commit +echo "temp edit" >> notes.txt +git diff + +# Compare staged vs last commit +git add notes.txt +git diff --staged + +# Compare two commits (use your own SHAs) +git log --oneline -n 2 +git diff HEAD~1 HEAD +``` + +## (Optional) Use a Hosted Remote +If you have GitHub/GitLab: +```bash +git remote set-url origin https://github.com//.git +git push -u origin main +git pull --rebase +``` + +## Outcome +You can push to and pull from a remote, and use `git diff` to compare changes. diff --git a/docs/07-view-history.md b/docs/07-view-history.md new file mode 100644 index 0000000..cb2ad8b --- /dev/null +++ b/docs/07-view-history.md @@ -0,0 +1,36 @@ +# Viewing the Commit History + +## Goal +Inspect commit history in different formats and levels of detail. + +## Basic Log +```bash +cd ~/lab-git-essentials/my-first-repo +git log +``` + +## One-Line, Decorated, with Graph +```bash +git log --oneline --decorate --graph --all +``` + +## Show a Specific Commit +```bash +# Copy a commit SHA from the log +git show +``` + +## Filter by File or Author +```bash +git log -- README.md +git log --author "Your Name" +``` + +## Statistics and Patches +```bash +git log --stat -n 5 +git log -p -n 1 +``` + +## Outcome +You can read history, view diffs, and filter logs by file or author. diff --git a/docs/08-undoing-things.md b/docs/08-undoing-things.md new file mode 100644 index 0000000..239c9ca --- /dev/null +++ b/docs/08-undoing-things.md @@ -0,0 +1,51 @@ +# Undoing Things + +## Goal +Learn safe ways to undo changes at different stages. + +## Discard Unstaged Working-Tree Changes +```bash +cd ~/lab-git-essentials/my-first-repo +echo "temporary" >> temp.txt +git status +git restore temp.txt # discard changes in working tree +git status +``` + +## Unstage Changes (Keep Edits) +```bash +echo "line" >> notes.txt +git add notes.txt +git status +git restore --staged notes.txt +git status +``` + +## Amend the Last Commit +```bash +echo "missed line" >> README.md +git add README.md +git commit --amend -m "Improve README with missed line" +git log --oneline -n 1 +``` + +## Revert a Commit (Safe in Shared History) +```bash +# Find a commit to revert +git log --oneline -n 5 +git revert +``` + +## Reset (Be Careful) +- `git reset --soft `: move HEAD, keep index and working tree +- `git reset --mixed `: move HEAD and reset index (default) +- `git reset --hard `: move HEAD, reset index and working tree (destructive) + +```bash +# Example: move HEAD back by 1 commit, keep changes in working tree +git reset --mixed HEAD~1 +git status +``` + +## Outcome +You can safely discard, unstage, amend, revert, and (carefully) reset. diff --git a/docs/09-tagging.md b/docs/09-tagging.md new file mode 100644 index 0000000..1d2b38e --- /dev/null +++ b/docs/09-tagging.md @@ -0,0 +1,36 @@ +# Tagging + +## Goal +Create and list tags and share them with remotes. + +## Lightweight vs Annotated Tags +- Lightweight: just a name pointing at a commit. +- Annotated: includes metadata (message, tagger), recommended for releases. + +## Create Tags +```bash +cd ~/lab-git-essentials/my-first-repo + +# Lightweight +git tag v0.1 + +# Annotated +git tag -a v1.0 -m "First stable release" + +# List tags +git tag -n +``` + +## Inspect a Tag +```bash +git show v1.0 +``` + +## Push Tags to Remote +```bash +git push origin v1.0 # push a single tag +git push origin --tags # push all tags +``` + +## Outcome +You can create, view, and push tags for versioning. diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..9dc49d9 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,16 @@ +# Git Essentials Lab (Ubuntu 24.04) + +This folder contains the step-by-step documents referenced by `lab.yaml`. + +Order of execution: +1. `docs/01-overview.md` +2. `docs/02-install-and-setup.md` +3. `docs/03-init-and-clone.md` +4. `docs/04-add-commit-status.md` +5. `docs/05-branch-checkout-merge.md` +6. `docs/06-pull-push-diff.md` +7. `docs/07-view-history.md` +8. `docs/08-undoing-things.md` +9. `docs/09-tagging.md` + +Time budget totals 60 minutes as defined in `lab.yaml`. diff --git a/lab.yaml b/lab.yaml index 9086837..328481c 100644 --- a/lab.yaml +++ b/lab.yaml @@ -1,16 +1,50 @@ -title: labzy -version: 1.0.0 -description: Descrition for tasks . -overview_path: docs/00_overview.md -sections: - title: Instructions - items: - - id: 1 - title: Task 1 - path: docs/01_task.md - estimated_minutes: 7 - dependencies: [] -ui: - default_open_section_id: 1 - show_toc: true - collapsible_sections: true \ No newline at end of file +lab: + id: git-essentials-ubuntu24 + title: Git Essentials in 1 Hour + description: "Hands-on introduction to Git covering history, installation, initialization, staging/committing, branching/merging, remotes (push/pull/diff), history inspection, undoing, and tagging." + duration: 60m + environment: + os: ubuntu-24.04 + prerequisites: + - Terminal access with sudo + dependencies: + - git + materials: + workspace_dir: ~/lab-git-essentials + steps: + - id: step-01-overview + title: A Short History of Git & What is Git? + doc: docs/01-overview.md + time: 5m + - id: step-02-install-setup + title: Installing Git & First-Time Git Setup + doc: docs/02-install-and-setup.md + time: 10m + - id: step-03-init-clone + title: git init & clone + doc: docs/03-init-and-clone.md + time: 8m + - id: step-04-add-commit-status + title: git add, commit & status + doc: docs/04-add-commit-status.md + time: 8m + - id: step-05-branch-checkout-merge + title: git branch, checkout & merge + doc: docs/05-branch-checkout-merge.md + time: 10m + - id: step-06-pull-push-diff + title: git pull & push & diff + doc: docs/06-pull-push-diff.md + time: 8m + - id: step-07-history + title: Viewing the Commit History + doc: docs/07-view-history.md + time: 5m + - id: step-08-undo + title: Undoing Things + doc: docs/08-undoing-things.md + time: 4m + - id: step-09-tagging + title: Tagging + doc: docs/09-tagging.md + time: 2m