Git is a software that allows you to keep track of changes made to a project over time. Git works by recording the changes you make to a project, storing those changes, then allowing you to reference them as needed.
< git init >
To turn the project directory into a Git project.
The word 'init' means initialize.
$ git init
# result example
Initialized empty Git repository in /home/ccuser/workspace/sorcerers-code/.git/
The command sets up all the tools Git needs to begin tracking changes made to the project.
< Git Workflow >
< Git Workflow >
A Git project can be thought of as having three parts: 1. A Working Directory: where you’ll be doing all the work: creating, editing, deleting and organizing files. 2. A Staging Area : where you’ll list changes you make to the working directory. 3. A Repository : where Git permanently stores those changes as different versions of the project.
< git status >
To check the status of the changes as you changed the contents of the working directory.
$ git status
# result example
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
init_test.rb
scene-1.txt
nothing added to commit but untracked files present (use "git add" to track)
Notice the file under Untracked files. Untracked means that Git sees the file but has not started tracking changes yet.
< git add >
In order for Git to start tracking the file, the file needs to be added to the staging area.
$ git add filename
# example
$ git add scene-1.txt
$ git status
# result example
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: scene-1.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
add_test.rb
init_test.rb
Notice that Git indicates the changes to be committed with “new file: scene-1.txt”. Here Git tells us the file was added to the staging area.
< git restore >
To discard changes that is not committed in the working directory.
$ git restore filename
< git diff >
To check the differences between the working directory and the staging area.
$ git diff filename
# example
$ git diff scene-1.txt
# result example
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
< git commit >
To permanently stores changes from the staging area inside the repository.
$ git commit
# example
$ git commit -m "Complete first line of dialogue"
one more bit of code is needed for a commit: the option-mfollowed by a message.
< Standard Conventions for Commit Messages >
1. Must be in quotation marks. 2. Written in the present tense. 3. Should be brief (50 characters or less) when using-m.