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:

  1. A Working Directory - a working area where you work, make changes, and organize files.

  2. A Staging Area - place to list the changes you are making in the Working directory.

  3. A Repository - where git stores changes in a permanent versions of the project.

Using a Git Project

  1. 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.

  2. A diagram of a Git Workflow.
  3. As the project develops, git status can return the current state of changes to the project.
  4. 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.
    1. Example: git add scene-3.txt scene-5.txt
    2. Alternatively, you can add all of the files in a directory using git add .. The . acts as a placeholder for all files.

  5. 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.
  6. 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:

  1. a unique code identifier for the commit.
  2. The author of the commit
  3. The date and time of the commit
  4. The commit message.

How to Backtrack in Git

  1. 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:

  2. git checkout HEAD {filename}

    This will restore the file in the working directory to the last commit completed against it.


  3. Another useful backtracking is required when you realize you staged a file but you actually don't want to include it in your commit.


  4. 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.

  5. Finally, the git head can be reset to any previous commit using a command.

  6. 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.


    A git reset diagram.

Additional Git Functions to know

In addition to the functions listed above, there are a few additional key git commands that are worth learning.

  1. 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 syntax git stash pop.
  2. Git Branch - git branch <brandName> allows a user to create new branches of our git code during its development.
  3. Git Log git log returns a log of all git commits, their comments, and the SHA/hash of the commits
  4. 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
  5. 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 as git co <filename>.