inter-git

Creating Repository (Exercise)

Working Directory

file
The folder is empty.

Repository

?

What is this area called?
That’s right!
Not quite, try again!

?

What is this area called?
You got it!
Not quite, try again!

Command Cheatsheet

git init
Starts a new Git repository in the current folder so Git can track changes.
git add <filename...>
Adds files from your working directory to the index so they can be included in the next commit.
git commit -m <message>
Adds files from the index to the object store with a message describing what you changed.
git mv <source-file> <destination-file>
Renames a file in both the working directory and the index.
git rm <file>
Remove a file from both the working directory and the index (staging area).
git rm --cache <file>
Remove a file from the index (staging area) but not from the working directory.
git status
Show the current state of the working directory and index.
git diff
Show changes between the working directory and the index.
git diff --cached
Show changes between the index and the last commit.
git show <commit-id>
Shows the details of a specific commit, including the author, date, message, and code changes. Great for reviewing what was changed in that commit.
git log
Shows a list of past commits in your project, including commit IDs, authors, dates, and messages.
git restore <file>
Copies the file from the staging area (index) to your working directory, discarding local changes.
git restore --staged <file>
Copies the file from the last commit to the staging area (index), unstaging it.
git branch <branch-name>
Creates a new branch with the given name.
git switch <branch-name>
Switches to the specified branch (recommended for newer Git versions).
git checkout <branch-name>
Also switches to the specified branch (older alternative to switch).
git branch
Lists all branches in your repository and highlights the current one.
git merge <branch-name> -m <message>
Merges the specified branch into your current one and adds a custom commit message.
git merge --abort
Stops a merge and resets everything back to how it was before the merge started.
git reset --soft <commit_id>
Moves HEAD to the given commit, making it the new last commit, but leaves the index and working directory unchanged.
git reset --mixed <commit_id>
Moves HEAD to the given commit and copies its files to the index, discarding old staged changes but keeping changes in the working directory.
git reset --hard <commit_id>
Moves HEAD to the given commit and copies its files to both the index and working directory, discarding all local changes completely.
touch <file-name>
Creates a new empty file with the specified name.
mv <source-file> <destination-file>
Moves or renames a file from one location to another.
cp <source-file> <destination-file>
Copies a file to a new location with the same or different name.
rm <glob pattern | <file>>
Deletes the specified file(s) permanently.
open <file>
Opens the specified file with the default application on your system.