update
This commit is contained in:
parent
3cd5ad457c
commit
daa6640c1e
|
|
@ -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.
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -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/<you>/<repo>.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.
|
||||||
|
|
@ -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 <SHA>
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
@ -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 <SHA>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Reset (Be Careful)
|
||||||
|
- `git reset --soft <target>`: move HEAD, keep index and working tree
|
||||||
|
- `git reset --mixed <target>`: move HEAD and reset index (default)
|
||||||
|
- `git reset --hard <target>`: 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.
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -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`.
|
||||||
66
lab.yaml
66
lab.yaml
|
|
@ -1,16 +1,50 @@
|
||||||
title: labzy
|
lab:
|
||||||
version: 1.0.0
|
id: git-essentials-ubuntu24
|
||||||
description: Descrition for tasks .
|
title: Git Essentials in 1 Hour
|
||||||
overview_path: docs/00_overview.md
|
description: "Hands-on introduction to Git covering history, installation, initialization, staging/committing, branching/merging, remotes (push/pull/diff), history inspection, undoing, and tagging."
|
||||||
sections:
|
duration: 60m
|
||||||
title: Instructions
|
environment:
|
||||||
items:
|
os: ubuntu-24.04
|
||||||
- id: 1
|
prerequisites:
|
||||||
title: Task 1
|
- Terminal access with sudo
|
||||||
path: docs/01_task.md
|
dependencies:
|
||||||
estimated_minutes: 7
|
- git
|
||||||
dependencies: []
|
materials:
|
||||||
ui:
|
workspace_dir: ~/lab-git-essentials
|
||||||
default_open_section_id: 1
|
steps:
|
||||||
show_toc: true
|
- id: step-01-overview
|
||||||
collapsible_sections: true
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue