Git Overview
Git is a software that enables tracking changes to a coding project over time. Git projects can be thought of as having 3 working parts:
A Working Directory - a working area where you work, make changes, and organize files.
A Staging Area - place to list the changes you are making in the Working directory.
A Repository - where git stores changes in a permanent versions of the project.
Using a Git Project
To start a Git Project, use the BASH terminal and navigate to where you intend to create a Git repositort. Type
git init
into the terminal to create the repository.- As the project develops,
git status
can return the current state of changes to the project. - To add files to the git tracking, use
git add filename
. This will add files to the scope of the project. Multiple files can be added at once by seperating filenames by a space. - Example:
git add scene-3.txt scene-5.txt
Alternatively, you can add all of the files in a directory using
git add .
. The . acts as a placeholder for all files.- To check on changes to the files, use
git diff filename
for each file return a summary of what has changed since the last commit. - A commit is the last step of a Git Workflow. To commit, type
git commit -m "Insert a description for the commit here"
. The description should be 50 characters or less.

Checking the log
Git history can be checked to see a log of commits. This is done by typing git log
into
the terminal. The resulting text shows:
- a unique code identifier for the commit.
- The author of the commit
- The date and time of the commit
- The commit message.
How to Backtrack in Git
In using Git, it may be necessary to backtrack a file that you have made a change to. To do this, use the following code command:
Another useful backtracking is required when you realize you staged a file but you actually don't want to include it in your commit.
Finally, the git head can be reset to any previous commit using a command.
git checkout HEAD {filename}
This will restore the file in the working directory to the last commit completed against it.
git reset HEAD {filename}
This script will reset the staged file to be the same as its last committed version. The file in the working directory won't be affected by this change.
git reset commit_SHA
The commit_SHA is the first 7 digits of the long SHA code obtained from a previous git commit. These
can be seen using the command Git log
.

Additional Git Functions to know
In addition to the functions listed above, there are a few additional key git commands that are worth learning.
- Git Stash - stash enables a user to temporarily store changes to a file to return to a clean commit
and make changes, recommit, and then once again load the in progress edits. This is done with the
command
git stash
. This stores current code. Users can then switch to an alternate branch to make and commit changes. To return to the stashed code, type the syntaxgit stash pop
. - Git Branch -
git branch <brandName> allows a user to create new branches of our git code during its development.
- Git Log
git log
returns a log of all git commits, their comments, and the SHA/hash of the commits - Git commit --amend - commit --amend enables a user to replace the last commit with the changes from
the current file, as well as with a new comment if desired. If no new comment is desired, the full command
should read
git commit --amend --no-edit
- Git aliasing - aliasing enables replacing the full text of some git commands with chosen shortcuts.
Example:git config --global alias.co "checkout"
- allows checkout to be performed as simply asgit co <filename>.
