0% found this document useful (0 votes)
90 views3 pages

Git and Github, Part I - Introduction To Git Cheatsheet - Codecademy

Git is a version control system that tracks changes to files in a project over time. The basic Git workflow involves editing files in the working directory, adding changed files to the staging area using "git add", and committing changes from the staging area to the repository using "git commit". Key Git commands include "git init" to initialize a repository, "git status" to check the status, "git diff" to view differences, and "git log" to see commit logs.

Uploaded by

ilias ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views3 pages

Git and Github, Part I - Introduction To Git Cheatsheet - Codecademy

Git is a version control system that tracks changes to files in a project over time. The basic Git workflow involves editing files in the working directory, adding changed files to the staging area using "git add", and committing changes from the staging area to the repository using "git commit". Key Git commands include "git init" to initialize a repository, "git status" to check the status, "git diff" to view differences, and "git log" to see commit logs.

Uploaded by

ilias ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Cheatsheets / Git and Github, Part I

Introduction to Git
Checking the Status of a Git Repository
The git status command is used within a Git repository
to its current status including the current commit, any
modified files, and any new files not being tracked by Git.
The output of git status can vary widely, and it often
includes helpful messages to direct the user to manage
their repository. For example, git status will show the
user the files they would commit by running git commit
and the files they could commit by running git add
before running git commit .

Initializing a Git Repository


The git init command creates or initializes a new Git
project, or repository. It creates a .git folder with all the $ cd /home
tools and data necessary to maintain versions. This $ git init
command only needs to be used once per project to
complete the initial setup. For instance, the code block
sets up the home folder as a new git repository.

Displaying Differences with Git Diff


The git diff filename command will display the
differences between the working directory and the $ git diff hello.txt
staging area in one specific file. Use git diff filename diff --git a/hello.txt b/hello.txt
before adding new content to ensure that you are making index 557db03..980a0d5 100644
the changes you expect. --- a/hello.txt
+++ b/hello.txt
@@ -1 +1 @@
-Hello World
+Hello World!
Showing Git Commit Logs
In Git, the git log command shows all of the commit
logs for a project. The following is displayed for each $ git log
commit: commit
9d63f80111447544c303e9f1776fa08593a87310
● A 40-character code, called a SHA, that uniquely
Author: codecademy
identifies the commit.
<[email protected]>
● The commit author Date:   Wed Jan 13 18:55:53 2021 +0000
● The date and time of the commit
    Added updates to the file
● The commit message

This command is particularly useful when you need to commit


refer back to an old version of your project. The unique 3ba6efbeece6ed530d85de5e313e52123fdf8cb4
SHA code allows you to identify a point in your program’s Author: codecademy
history that you would like to revert to.
<[email protected]>
Date:   Wed Jan 6 10:11:13 2021 -0400

    Completed first line of dialogue

Committing Your Code


The git commit -m "log message here" command creates
a new commit containing: $ git commit -m "Added About section to
README"
● The current contents of the staging area
[master 9d63f80] Added About section to
● A log message describing the changes to the README
repository 1 file changed, 10 insertions(+),
1 deletion(-)
A commit is the last step in our Git workflow. A commit
permanently stores changes from the staging area inside
the repository. This command is almost always used in
conjunction with the git add command as git add is
used to add files to the staging area.

Git
Git is a command line software that keeps track of
changes made to a project over time. Git works by
recording the changes made to a project, storing those
changes, then allowing a programmer to reference them
as needed.
All Git commands follow the pattern git <action> and, in
order to use Git for a project, a project must first be
initialized using the git init command in the project’s
root directory.
Adding Changes to the Staging Area
The git add filename command is used to add the
filename file to the staging area. After your changes have
been staged, you can use the git commit command to
permanently store your changes.

Git Project Workflow


A Git project has three parts:

● A Working Directory: where files are created,


edited, deleted, and organized

● A Staging Area: where changes that are made to the


working directory are listed

● A Repository: where Git permanently stores


changes as different versions of the project

The Git workflow consists of editing files in the working


directory, adding files to the staging area, and saving
changes to a Git repository.

You might also like