Master the fundamental concepts and commands of Git, including:
Using init to start tracking. Changing default branch name, making edits, staging, and committing.
git init
git branch -M master
echo test > test
git add .
git commit -m "test"
git log
๐ The git init command creates a hidden .git folder.

Adding another file and committing. Letโs see the history growth.
echo test2 > test2.txt
git add . && git commit -m "test2"
git log

Using short logs to visualize history properly.
echo test3 > test3.txt
git add . && git commit -m "test3"
git log --oneline
git log --oneline --graph
๐ --oneline --graph visualizes the branch history in a concise format.

Reviewing unsaved changes before a commit.
echo test3secondline >> test3.txt
git diff
git status
๐ git diff shows the exact line changes in modified files.
๐ git status distinguishes between modified and untracked files.

Creating new files to observe git status output.
echo test4secondline >> test4.txt
git status

Saving the specific modifications shown above.
git commit -m "test3 modified"
git status

Creating and navigating between branches.
git branch main
git switch main
git checkout master
๐ git branch creates or lists branches. git switch or git checkout change the active branch.

Checking out a specific point in time (commit hash).
git log --oneline --graph
git checkout f246397
git checkout main
๐ Warning: When in โdetached HEADโ, changes arenโt associated with a branch unless a new branch is explicitly created.

Deleting the master branch.
git branch && git branch -D master

Creating a new branch to keep specific snapshot commits.
# While detached at an older commit
git branch feature
git branch

Attempting a merge when the current branch has the history of the target.
git checkout main
git merge feature

git checkout feature
echo "dummy feature" > feature.txt
git add .
git commit -m "feature added"

# From main branch
git merge feature
git log --oneline --graph
๐ This creates a true merge commit combining the history of both branches.

| Command | Description |
|---|---|
git init |
Initialize a new Git repository |
git add <file> |
Stage changes for commit |
git commit -m "msg" |
Save staged changes with a message |
git status |
Show the state of the working directory |
git log |
Show commit history |
git diff |
Show changes between commits/working tree |
git branch |
List, create, or delete branches |
git checkout |
Switch branches or restore working tree files |
git merge |
Join two or more development histories together |
Git is essential for version control, allowing developers to track changes, collaborate effectively, and revert to previous states if something goes wrong. Understanding branches and merges is the key to managing complex projects.
| โ Previous Class | Theory Index |