Git is the industry-standard version control system that allows multiple developers to work on a project simultaneously by tracking changes and coordinating work.

This is a quick reference cheat sheet for understanding and writing Git.
Git is the industry-standard version control system that allows multiple developers to work on a project simultaneously by tracking changes and coordinating work.
Creates a new .git folder and initializes version control.
git init
Initialized empty Git repository in /home/ccuser/workspace/manhattan-zoo-1/.git/
Shows untracked or modified files, and branch info.
git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
scene-1.txt
nothing added to commit but untracked files present (use "git add" to track)
Adds single, multiple or all modified files to staging.
git add filename_you_are_editing
git add file1 file2
git add .
git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: scene-1.txt
Shows what changed in your files before committing.
git diff
diff --git a/scene-1.txt b/scene-1.txt
index c33ce4c..1e73963 100644
--- a/scene-1.txt
+++ b/scene-1.txt
@@ -1 +1,2 @@
Harry Programmer and the Sorcerer’s Code: Scene 1
+Dumblediff: I should've known you would be here, Professor McGonagit.
\ No newline at end of file
Add a message with -m
in present tense, 50 chars max.
git commit -m "Complete first line of dialogue"
[master (root-commit) a659c51] Prima riga di codice fatta
1 file changed, 2 insertions(+)
create mode 100644 scene-1.txt
git log
Lists commits in reverse chronological order.
commit a659c518f418547ce82b4557a86ffcee61ee33f4
Author: codecademy <ccuser@codecademy.com>
Date: Sun Oct 27 22:00:38 2024 +0000
Prima riga di codice fatta
Displays the latest commit’s metadata and all file changes it includes.
git show HEAD
commit fa2706aa2214a3e6b3ba1d2f62b4acbf9c04fcce
Author: codecademy <ccuser@codecademy.com>
Date: Sun Oct 27 22:18:14 2024 +0000
ghost response scene 5
diff --git a/scene-5.txt b/scene-5.txt
index b12dd97..fa75b29 100644
--- a/scene-5.txt
+++ b/scene-5.txt
@@ -11,4 +11,7 @@ Mark me.
Hamlet:
I will.
-
+Ghost:
+My hour is almost come,
+When I to sulphurous and tormenting flames
+Must render up myself.
Reverts a file to its state in the last commit.
git checkout HEAD filename
Restores a file from the latest commit.
git checkout -- filename
Same as git checkout HEAD filename
Removes a file from the staging area (keeps changes in working directory).
git reset HEAD filename
Unstaged changes after reset:
M scene-2.txt
Moves the repo back to a previous commit (by SHA).
git reset 5d69206
Modes of reset
Resets all files in working directory to match HEAD.
git checkout -- .
This discards local changes not yet staged or committed.
Temporarily stores changes in the working directory that are not yet ready to be committed. Useful when you need to switch branches or fix a different issue before resuming work.
Saves uncommitted changes and clears the working directory.
git stash
Used when an interruption occurs and you need to save progress temporarily.
Restores the most recently stashed changes and removes them from the stash list.
git stash pop
Use after resolving the interruption to resume your previous work.
Displays each commit on one line (short SHA and message).
git log --oneline
Finds commits where the number of keyword occurrences changes.
git log -S "Add"
Matches commits where "Add" was added or removed.
Shows a graphical representation of branch history.
git log --oneline --graph
Helpful to visualize merges and branch structure.
Rewrites the last commit (useful to fix message or add changes).
git commit --amend
Replaces the last commit instead of adding a new one.
If you want to keep the same commit message:
git commit --amend --no-edit
Shorten frequently used commands via Git config.
git config --global alias.co "checkout"
git config --global alias.br "branch"
git config --global alias.glop "log --pretty=format:\"%h %s\" --graph"
After defining, you can use git co example_branch
instead of git checkout example_branch
Show decorated, compressed graph of all commits:
git log --graph --decorate --oneline --all