🚨 $100K in Sight: Follow Bitcoin’s Final Push Live! TRACK NOW

Code has been added to clipboard!

A Useful Git Cheat Sheet: Learn About File Stages and Common Commands

Reading time 4 min
Published Jan 31, 2018
Updated Oct 3, 2019

This Git cheat sheet includes information necessary for managing and updating your projects.

Git Cheat Sheet: Main Tips

  • Files in Git have several states: modified, staged, or committed.
  • Git is a version control system meaning that it helps users keep track and manage changes of projects. It is also possible to revert to older versions.

Git: Best Practices

When using Git for your projects, it is best to set certain rules and limitations for managing your work. Here are a few best practices of Git that you and your contributors should follow:

  • Submit commits that address a particular issue or change. When you are updating one specific section of your project, do not make other modifications.
  • Organize your work and make commits often. Commits make sure that nothing gets lost.
  • Every commit should be described clearly. Indicate the changes you made to make sure that other contributors can follow up easily.
  • Do not change the history of commits unless specific conditions require you to do it.
  • Test your changes before committing. If your commit fixes a bug, make sure that it does.

The Life Cycle of Git Files

Git Cheat Sheet

When working with Git repositories, you will add, delete, and edit files (with init, add and commit commands).

You need to learn that files in your working directory can be either tracked or untracked. Here is an explanation of how does Git files work:

  • Tracked files are the ones that Git has been informed about. They can be modified, unmodified, or staged.
  • Untracked files refer to files that are not in the staging area and not in the latest snapshot.
DataCamp
Pros
  • Easy to use with a learn-by-doing approach
  • Offers quality content
  • Gamified in-browser coding experience
  • The price matches the quality
  • Suitable for learners ranging from beginner to advanced
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid Certificates of completion
edX
Pros
  • A wide range of learning programs
  • University-level courses
  • Easy to navigate
  • Verified certificates
  • Free learning track available
Main Features
  • University-level courses
  • Suitable for enterprises
  • Verified certificates of completion

Three Stages of Edited Files

In general, Git sees the files you edit as modified. It is standard that you stage the modified files and then commit the changes you have made.

Here is a short explanation of each state:

  • Modified — the file has been changed, but not yet committed to the database.
  • Staged — the current version of the modified file has been proposed by you to commit.
  • Committed — means that the changes to data have been stored in the database.

Version Control System

The Git version control consists of making snapshots of projects. In other words, version control keeps track of all your changes and allows reverting in case the changes bring issues.

How Git Works: Step by Step

This list shows how does Git work:

  • You begin with cloning Git repository as a working copy.
  • By editing or adding files, you modify the working copy.
  • You update the working copy by taking over the changes other developers made.
  • You review the changes and decide if and which ones to commit.
  • You check if there are no mistakes and move the changes to the repository with the Git commit command.
  • If you notice mistakes or issues, you can always correct the last commit and update the changes.

To describe this Git workflow cheat sheet in a more terms-filled manner, it would look like this:

  • You modify or change files in a working tree (also called working directory or area).
  • Select and stage only the files that you want to commit. Those particular changes are added to the index (a technical term for staging area).
  • You commit a snapshot of those changed files, and they land to the repository (.git directory or the HEAD).
  • Do not be confused over the use of commit and push. Commit command adds changes to the local repository, while push does the same but sends commits to remote servers.

Git Cheat Sheet: Summary

  • Best practices of Git include committing often, clearly describing changes, and focusing on one issue in one commit.
  • There are several file stages. Make sure that Git saves the files and changes to them.