0% found this document useful (0 votes)
147 views43 pages

Mastering Git & GitHub Essentials

Learning Git and GitHub is essential for tech professionals as it facilitates collaboration, project management, and enhances job opportunities. The document provides a glossary of key terms, resources for learning, and best practices for using Git and GitHub effectively. It also includes tips, tricks, and a quick command cheatsheet to help users navigate Git more efficiently.

Uploaded by

maduri15251
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)
147 views43 pages

Mastering Git & GitHub Essentials

Learning Git and GitHub is essential for tech professionals as it facilitates collaboration, project management, and enhances job opportunities. The document provides a glossary of key terms, resources for learning, and best practices for using Git and GitHub effectively. It also includes tips, tricks, and a quick command cheatsheet to help users navigate Git more efficiently.

Uploaded by

maduri15251
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

Learn Git & Git Hub

Why Learn Git & GitHub?


Learning Git and GitHub is one of the most important steps for anyone in the tech industry. It's not just
about coding; it's about efficient collaboration and professional development.

To Contribute to Open Source: The world of open-source software runs on Git and GitHub. Learning
them allows you to contribute to projects you love, fix bugs, add features, and become part of a global
community.

To Effectively Manage Projects: Whether you're working alone or on a team, Git provides a powerful
way to track changes, experiment with new ideas in branches without risk, and easily revert to a
previous version if something goes wrong. It's like having a complete history of your project at your
fingertips.

To Open New Opportunities: A strong GitHub profile acts as a modern resume for developers. It
showcases your work, your coding style, and your collaboration skills to potential employers. Many
companies will look at your GitHub profile before they even look at your CV.

To Have a Key Skill That Makes You Versatile: Git and GitHub are industry standards. Knowing them is
a fundamental skill expected in almost every software development, DevOps, data science, and even
technical writing role. It makes you a more adaptable and valuable team member.

Learn Git & Git Hub 1


What is What? A Simple Glossary
Git: The tool on your computer that saves "snapshots" of your project. It's the version control system
itself.

GitHub: The website where you store your projects online. It's a platform for collaboration and sharing
your Git repositories.

Repository (Repo): A folder for your project that contains all your files and the entire history of changes
( .git folder).

Commit: A "snapshot" or a save point of your project at a specific time. Each commit has a unique ID
and a message describing the changes.

Branch: An independent line of development. You create branches to work on new features or bugs
without disturbing the main, stable version of your code (often called the main branch).

Pull Request (PR): A request to merge your changes from one branch into another (usually your feature
branch into the main branch). It's the starting point for code review on GitHub.

Resources to Learn
Here are some of the best places to master Git and GitHub:

GitHub Skills: Interactive, bot-led courses directly within GitHub. It's a great hands-on way to learn.

Learn Git & Git Hub 2


Learn Git Branching: An excellent interactive tutorial for visualizing and understanding how branches,
merges, and rebasing work.

The Pro Git Book: The official book, available for free online. It's comprehensive and covers everything
from beginner to advanced topics.

YouTube Channels: Channels like Fireship, The Net Ninja, and FreeCodeCamp have fantastic video
tutorials that walk you through the entire workflow.

Git & GitHub Tutorial | Visualized Git Course for Beginner & Professional Developers in 2024
In this visualized Git Tutorial, you'll learn everything from the basics of Git to advanced tips no one else
talks about. We’ll dive into real-world Git workflows, fixing production issues, and resolving merge
conflicts like a pro. By the end, you'll be your team's go-to Git expert, ready to handle any challenge!
[Link]

Git and GitHub - 0 Experience to Professional in 1 Tutorial (Part 1)


Learn Git from 0 experience to professional level in 3 projects.

Git Cheatsheet: [Link]


[Link]

Git & GitHub Crash Course 2025


This is a crash course to learn the fundamentals of Git version control and the Github
platform. Learn all of the core commands and the workflow to start learning Git.

[Link]

Complete git and Github course in Hindi


Welcome to complete git and github series in Hindi. In this video we will learn about Git in
depth along with workflow so that you can use git in your daily life. Further we will explore
about github so that you can store your code online in an easy way. Not only that, we have
[Link]

Complete Git and GitHub Tutorial for Beginners


Hey Everyone, In this video, We will understand the Version Controlling System using GIT
and GitHub. We'll see what is Git and How to get started with Git and GitHub.

[Link]

Complete Git and GitHub Tutorial for Beginners


Hey Everyone, In this video, We will understand the Version Controlling System using GIT
and GitHub. We'll see what is Git and How to get started with Git and GitHub.

[Link]

Complete Git and GitHub Tutorial for Beginners


Link for GitHub Notes :
[Link]
usp=share_link
[Link]

Learn Git & Git Hub 3


Github in Telugu | Complete Git & GitHub in 1 hour | Vamsi Bhavani | A to Z in Git Github
In this video you will learn completely about what is git, what is github, what is vcs, what is
repository, what is staging area, what are commits from beginner level to advanced level. So, do
watch it completely to get complete clarity.
[Link]

Git and GitHub for Poets


This course is designed to teach you the basics of working with git version control and the
GitHub website. Learning Objectives: * Understand the concept of ...

[Link]

Git
The source of this book is hosted on GitHub.
Patches, suggestions and comments are welcome.
[Link]

[Link] Help Documentation


Get started, troubleshoot, and make the most of GitHub. Documentation for new users,
developers, administrators, and all of GitHub's products.

[Link]

GitHub Student Developer Pack


The best developer tools, free for students. Get your GitHub Student Developer Pack now.

[Link]

[Link]

Version Control with Git | Udacity


Learn online and advance your career with courses in programming, data science, artificial
intelligence, digital marketing, and more. Gain in-demand technical skills. Join today!

[Link]

Learn Git Branching


An interactive Git visualization tool to educate and challenge!

[Link]

An Intro to Git and GitHub for Beginners (Tutorial)


A step-by-step tutorial for beginners to get started with git and GitHub.

[Link]

Learn Git & Git Hub 4


Learn Git & GitHub In-depth
A deep dive into git, this course is for developers who use git and GitHub every day and
want to learn the inner workings and use advanced techniques.

[Link]

The Git Parable


Git is a simple, but extremely powerful system. Most people try to teach Git by
demonstrating a few dozen commands and then yelling “tadaaaaa.” I believe this
method is flawed. Such a treatment may leave you with the ability to use Git to
[Link]

Top Tips and Tricks ⭐


Good Commit Messages are Key: Write clear, concise commit messages. A common practice is to start
with a verb (e.g., "Fix: login bug") or a type (e.g., "Feat: Add user profile page").

Use .gitignore : Create a .gitignore file in your repository to tell Git which files or folders it should ignore
(like log files, dependency folders, or secret keys).

Branch Early, Branch Often: Don't be afraid to create a new branch for even the smallest change. It
keeps your main branch clean and makes your work easier to manage.

Pull Before You Push: Always run git pull to get the latest changes from your team before you git push

your own work. This helps prevent merge conflicts.

Use Aliases: Speed up your workflow by creating shortcuts for common commands in your Git
configuration. For example, git co for git checkout or git st for git status .

These tricks transform a standard GitHub URL like this:


[Link]

## 💻 Instantly Open Repos in an Online Editor


You can browse and search through code in a familiar IDE-like environment directly in your browser without
cloning the repository.

Open in a VS Code Interface


Purpose: To get a speedy, read-only VS Code experience for any repository.

The Trick: Add 1s after github .

Example URL: [Link]

Open in the Official GitHub Editor


Purpose: Use GitHub's official web-based editor, which is essentially VS Code for the web. You can
even make and commit changes if you have the permissions.

The Trick: Change .com to .dev .

Example URL: [Link]

Open in CodeSandbox

Learn Git & Git Hub 5


Purpose: To not only view the code but also run it in an online development environment (a "sandbox").
This is perfect for trying out web projects.

The Trick: Add box after github .

Example URL: [Link]

## 🧠 Analyze and Understand Repositories


These tools help you quickly understand the structure, purpose, and content of a repository.

Get an AI-Powered Explanation


Purpose: To use an AI tool that analyzes the repository and provides a high-level explanation of what it
does.

The Trick: Replace [Link] with [Link] .

Example URL: [Link]

Visualize the Codebase


Purpose: To convert a repository into an interactive, visual diagram that helps you understand how the
files and components connect.

The Trick: Prefix the URL with [Link] .

Example URL: [Link]

View a File Tree Structure


Purpose: To get a clean, text-based directory tree of the entire repository, which is great for
documentation or a quick overview.

The Trick: Prefix the URL with [Link] .

Example URL: [Link]

## 📄 Convert to Different Formats


Get a Markdown Summary
Purpose: To generate a structured Markdown document from the repository's contents, useful for
documentation.

The Trick: Replace github with gitingest .

Example URL: [Link]

## ✨ Bonus Git Command Line Trick


This isn't a URL trick, but it's an incredibly useful command for your terminal.

Quickly Switch to Your Last Branch


Purpose: To switch back to the previously checked-out branch without needing to remember or type its
full name.

The Command: git checkout -

How it Works: The is a shortcut in Git for the last branch you were on. For example, if you switch from
main to feature-branch , running git checkout - will take you right back to main .

Learn Git & Git Hub 6


What GitHub "tricks" do you wish you knew about earlier?
42 votes, 38 comments. 163K subscribers in the github community. A subreddit to discuss GitHub's platform, products and features. Not
affiliated with GitHub, Inc. Please note that r/git exists and is a better place to ask Git-related questions.
[Link]

Quick Command Cheatsheet 📝


Here are the commands you'll use most often.

Command Description
git init Initializes a new Git repository in your current folder.
git status Shows the status of your changes.
git add . Stages all files in the current directory for the next commit.
git commit -m "Message" Commits your staged changes with a descriptive message.
git log --oneline Shows a condensed history of your commits.
git switch -c <branch-name> Creates a new branch and switches to it.
git switch <branch-name> Switches to an existing branch.
git merge <branch-name> Merges the specified branch into your current branch.
git push origin <branch-name> Pushes your branch and its commits to the remote repo (GitHub).
git pull origin <branch-name> Pulls the latest changes from the remote repo to your local one.

✅ Git & GitHub Best Practices


[Link]

🟢 Do’s
Commits & Branches

Think of commits as achievements, not just save points.

Keep commits small, coherent, and meaningful.

Always check your commits before pushing.

Use feature branches for new work.

Squash trivial commits (“fix typo”, “update docs”) before merging.

Merge/rebase often to avoid large, messy updates.

Commit Messages

Write clear commit messages:

Title/first line: short summary of what the commit does.

Body: explain why the change is being made (if not obvious).

Use an editor, not just git commit -m "msg" .

Enable helpful configs like:

Learn Git & Git Hub 7


git config --global [Link] true

Good Practices

Always git rebase before sending a Pull Request.

Use git stash for temporary changes instead of git reset .

Add a .gitignore file instead of manually unchecking files.

Learn Git from the command line first, then explore GUIs.

Use git status often — it guides your next steps.

Use tools to view commit history:

git log --oneline --all --graph

Or install tools like tig or use gitk (comes by default).

Configure your shell prompt to show the current branch.

🔴 Don’ts
Don’t put unrelated changes in a single commit.

Don’t write lazy commit messages.

Don’t use git pull without -rebase .

Don’t use git reset blindly (stash instead).

Don’t keep separate long-lived dev and main branches — it causes confusion.

Don’t blindly copy-paste Git commands from the internet.

Don’t use git add . or git commit -a (they add unintended files).

Instead:

git add -u # Add only tracked files


git add file # Add manually

⚡ Quick Pro Tips


Use git pull --rebase instead of plain git pull .

Use [Link]=only config to prevent messy merges:

git config --global [Link] only

Check commit history visually with:

tig

Think of branches as features, not permanent environments.

Build a mental model of Git — don’t just memorize commands.

Learn Git & Git Hub 8


✨ With these practices, you’ll avoid common Git headaches, write professional commit history, and make
collaboration smoother.

Happy Learning! Share this guide with friends who want


to upgrade their skills!
Follow for More Resources & Guidance:
💪
📚 Goutham Sankeerth
🎥 YouTube: [Link]
📱 Instagram: @gouthamsankeerth
🔗 All Resources & Links:
Goutham Sankeerth - Linktree

📝 Note: This document reflects personal experiences, insights from colleagues, friends, and various
online resources (Google, YouTube, Reddit, etc.), formatted with AI assistance for better readability. Hope
this helps you on your journey!

- Goutham Sankeerth

Introduction to Git & GitHub


Git is a version control system (VCS). Think of it as a "save" button for your entire project, but with
superpowers. It allows you to track changes to your files, revert to previous versions, and collaborate with
others without overwriting their work. It's a program that runs on your local computer. 💻
GitHub is a web-based hosting service for Git repositories. It's a platform where you can store your
projects (repositories) online. It provides a user interface and tools for collaboration, like tracking issues,
reviewing code, and managing projects. It's where your Git projects live on the internet. ☁️
In short: Git tracks your changes, and GitHub helps you share and collaborate on those changes with
others.

The Complete Learning Roadmap


This roadmap will take you from a complete beginner to a confident user.

1. Setup & The Basics (Your Local Machine)


First, you need to get Git working on your computer.

Installation & Configuration


1. Install Git: Download and install it from the official Git website.\

Git - Downloads
The entire Pro Git book written
by Scott Chacon and Ben Straub is available to read online for free.
Dead tree versions are available on [Link].
[Link]

1. Configure Git: After installation, open your terminal (or Git Bash on Windows) and introduce yourself to
Git. This information is attached to every commit you [Link]

Learn Git & Git Hub 9


git config --global [Link] "Your Name"
git config --global [Link] "[Link]@[Link]"

Core Concepts: The Three Trees 🌳


Understanding this is key to "getting" Git. Your project has three main states:

1. Working Directory: The actual folder with your project files that you are currently editing.

2. Staging Area (Index): A "drafting" area where you prepare the specific changes you want to save in
your next "snapshot" (commit).

3. Repository ( .git directory): The database where Git permanently stores all the snapshots (commits) of
your project's history.

The Basic Workflow


This is the cycle you'll use 90% of the time.

1. Initialize a Repository: Go into your project folder and run this command [Link]
git init

This creates the hidden .git directory, turning your project into a Git repository.

2. Check the Status: See what's happening—which files are new, modified, or [Link]
git status

3. Stage Your Changes: Add the files you want to include in your next [Link]
# Stage a specific file
git add [Link]

# Stage all new and modified files in the current directory


git add .

4. Commit Your Changes: Save your staged changes to the repository with a descriptive [Link]
git commit -m "Your descriptive message here"

For example, git commit -m "Feat: Add user login functionality" .

5. View History: See a log of all your [Link]


git log

⭐ Short Tricks & Tips:


Alias git status : Use git status -s for a short, compact view.

Better Log: Use git log --oneline --graph --all for a clean, visual history of all branches.

Add & Commit: Combine staging and committing with git commit -am "Your message" . This only works for files
that are already tracked (not new files).

2. Branching & Merging (Working in Parallel)


Branches are the killer feature of Git. They let you work on new features or bug fixes in an isolated
environment without affecting your main codebase (the main or master branch).

How to Use Branches


1. Create a New Branch:Bash
# Create a new branch named 'new-feature'
git branch new-feature

2. Switch to the New Branch:Bash


# Move to the 'new-feature' branch to start working
git switch new-feature

Learn Git & Git Hub 10


3. Work and Commit: Now you can make changes, git add , and git commit as usual. These commits will only
exist on the new-feature branch.

4. Merge Your Changes: Once your feature is complete, switch back to your main branch and merge the
feature branch into [Link]
# Go back to the main branch
git switch main

# Merge the 'new-feature' branch into 'main'


git merge new-feature

All the commits from new-feature are now part of main .

5. Delete the Branch (Optional): After merging, you can clean up by deleting the feature [Link]
git branch -d new-feature

⭐ Short Tricks & Tips:


Create and Switch: Combine creating and switching to a new branch with one command: git switch -c

<branch-name> or git checkout -b <branch-name> .

Merge Conflicts: If you and another person edit the same line of the same file on different branches, Git
won't know which version to keep. This is a merge conflict. Git will mark the file, and you'll have to
manually edit it to resolve the conflict before you can complete the merge.

3. GitHub & Remotes (Collaboration)


Now let's put your local Git repository on GitHub to share it.

The Remote Workflow


1. Create a Repository on GitHub: Go to [Link], create a new repository. Do not initialize it with a
README.

2. Connect Your Local Repo to GitHub: Copy the URL provided by GitHub and link your local repository to
the remote one on GitHub. We usually name the remote origin .Bash
git remote add origin <[Link]>

3. Push Your Code: Send your local commits (from your main branch) to the remote repository
( origin ).Bash
# The -u flag sets the upstream so next time you can just use 'git push'
git push -u origin main

The Daily Collaboration Cycle


1. Pull Changes: Before you start working, always get the latest changes from the remote repository to
avoid [Link]
git pull origin main

This command is actually two commands in one: git fetch (downloads remote changes) + git merge

(merges them into your local branch).

2. Work Locally: Create a branch, add your commits, etc.

3. Push Your Branch: When you're ready to share your new feature branch, push it to the [Link]
git push origin new-feature

4. Create a Pull Request (PR): On GitHub, you'll see a prompt to create a Pull Request for your newly
pushed branch. A PR is a request to merge your changes into the main branch. This is where your team
can review your code, leave comments, and approve the merge.

⭐ Short Tricks & Tips:

Learn Git & Git Hub 11


SSH vs. HTTPS: Use SSH keys for authentication. It saves you from typing your username and
password every time you push or pull.

Forking: If you want to contribute to a project you don't own, you fork it. This creates a personal copy
of the repository on your GitHub account. You then push changes to your fork and create a PR from
your fork to the original project.

4. Essential "Oops!" Commands (Fixing Mistakes)


Mistakes happen. Here’s how to fix them.

Unstage a File: You used git add but want to undo [Link]
git restore --staged <file-name>

Undo Local Changes: Revert a file back to how it was at the last commit (discards your changes!).Bash
git restore <file-name>

Amend the Last Commit: Forgot to add a file or made a typo in the commit message?Bash
# Stage your forgotten file(s) first with git add
git commit --amend

This opens an editor to change the last commit message. Warning: Don't do this on commits you've
already pushed!

Revert a Commit: To safely undo a public commit, create a new commit that does the [Link]
git revert <commit-hash>

Summary & Next Steps


1. Local Workflow: status -> add -> commit .

2. Branching: switch -c <branch> -> work -> switch main -> merge <branch> .

3. Remote Workflow: pull -> do your work -> push -> create a Pull Request on GitHub.

To keep learning:

Practice: Create your own projects and use Git for everything.

Contribute: Find a small open-source project on GitHub and try to fix a typo or a small bug. It's the best
way to learn the collaboration workflow.

Explore: Learn about git rebase , git cherry-pick , and git stash once you are comfortable with the basics.

Set up Git - GitHub Docs


At the heart of GitHub is an open-source version control system (VCS) called Git. Git is
responsible for everything GitHub-related that happens locally on your computer.

[Link]

Learn Git & Git Hub 12


🏑
Git & GitHub 101

Basic CLI Commands Working with Existing Projects on


1. To list all files or folder in a folder GitHub
ls Use Git Bash for Windows.
2. Make a new folder You can't directly change the contents of a repo unless
mkdir folder_name you have access to it. To solve this, you create a copy
(fork) of this project in your own account. In our own copy,
3. Go inside a folder
we can do anything we want with it. After forking, we:
cd folder_name

1. Cloning the forked project to local machine


4. To delete a whole non-empty directory/folder
git clone forked_repo_url
rm directory_name -rf

2. The public repo that we forked out local copy from is


5. Write a file in Git Bash Vim
known as the upstream url. We can save it as
vim file_name
git remote add upstream insert_upstream_url

1. use insert key to enable the writing mode in any 3. Creating a new branch
file
git branch branch_name

2. then after finishing edits, press the left-right arrow 4. Then shift the head to the above branch using the
key to disable the writing mode and then write :x checkout command
to exit out
5. Then stage. Then commit.

6. Then push. We can't push to upstream (no access).


6. Copy + Paste in CLI Can push to our forked repo though (origin)
1. Use the insert key to paste in CLI or highlight the git push origin your_branch_name
statement then right click and copy that statemen
and then right-click on CLI 7. Always make different branches for different pull
shows the options.
requests if you're working on different features. 1
Basic Git Commands branch = 1 pull request (never commit on main (2))
1. To make a new file 8. To remove a commit
touch [Link]
1. we can remove a commit with the reset command
2. To check if git is installed in your PC Now it's unstaged.
git
2. then add. to stage the remaining files
3. To initialize an empty Git repository in your folder
3. then we can use the stash command to stash it
git init
elsewhere
4. To view the changes or the untracked files in the
4. then, we'll have to force push this branch since the
project that's not been saved yet
online repo contains a commit which the local repo
git status
does not
5. Staging the files git push origin your_branch_name -f

git add file_name or git add . (to stage everything in 9. To make forked project even (updated) with the main
the current folder) project
6. Committing the files

Git & GitHub 101 1


git commit -m "your_message_here"
1. Shift the head to your main branch
7. To unstage or remove a file from the staging level git checkout main

git restore --staged file_name.txt


2. Fetching all the commits/changes from the main
8. To view the entire history of the project project (upstream)
git log git fetch --all --prune (here prune gets deleted
9. Removing a commit from the history of a project commits too)
git reset 3. Reset the main branch of origin (forked) to main
insert_commit_hash_id_to_which_you_want_to_go_back_to_here
branch of upstream (main project)
(all the commits or changes before this will go back to
git reset --hard upstream/main
the unstaged area now)
4. Check and verify your changes
10. After you stage a few files but then you want to have a
clean codebase or reuse those files later, we can git log click q for exit from log
stash those changes to go back to the commit before 5. Then push all these local changes to your online
they were staged forked repo
git stash git push origin main

11. Bringing back those changes or pop them from the Method 2
stash
1. To fetch all at once
git stash pop
git pull upstream main
12. To clear the changes or files in your stash
2. Then push to the origin url or your forked project
git stash clear
git push origin main

Method 3
How Git works
1. Update using the Fetch Upsteam button on forked
1. Connecting your Remote Repository to Local repo
Repository
10. Squashing all your multiple commits into one commit
git remote add origin insert_https_project_link_here
git rebase -i
2. Pushing local changes to remote repository insert_hash_code_of_commit_above_which_all_your_required_co

(we're pushing to the url origin,


git push origin master If there's 4 commits. Keep 1 as the pick and then s or
and the branch master) squash the other 3 into that one

3. To view all your remote urls 11. Merge conflicts and how to resolve them
git remote -v 1. They happen when multiple users edit the same
4. Never commit on the main branch since it's the one code line and then push it. Git won't know which
used by the people, to prevent any mishaps one to merge and then there'd be a conflict

5. Shifting the head to a branch (head is the pointer 2. This has to be resolved manually by repo
which points to where all you do your changes) maintainer
git checkout branch_name

6. Merging your branch to main of project


git merge branch_name

[Link]
-[Link]

Git & GitHub 101 2


GIT CHEAT SHEET

Git is the free and open source distributed version control system that's responsible for everything GitHub
related that happens locally on your computer. This cheat sheet features the most important and commonly
used Git commands for easy reference.

INSTALLATION & GUIS STAGE & SNAPSHOT


With platform specific installers for Git, GitHub also provides the Working with snapshots and the Git staging area
ease of staying up-to-date with the latest releases of the command
line tool while providing a graphical user interface for day-to-day git status
interaction, review, and repository synchronization.
show modified files in working directory, staged for your next commit
GitHub for Windows
git add [file]
[Link]
add a file as it looks now to your next commit (stage)
GitHub for Mac
[Link] git reset [file]

unstage a file while retaining the changes in working directory


For Linux and Solaris platforms, the latest release is available on
the official Git web site. git diff

Git for All Platforms diff of what is changed but not staged
[Link]
git diff --staged

diff of what is staged but not yet committed

SETUP git commit -m “[descriptive message]”


Configuring user information used across all local repositories commit your staged content as a new commit snapshot

git config --global [Link] “[firstname lastname]”

set a name that is identifiable for credit when review version history
git config --global [Link] “[valid-email]”
BRANCH & MERGE
Isolating work in branches, changing context, and integrating changes
set an email address that will be associated with each history marker
git branch
git config --global [Link] auto
list your branches. a * will appear next to the currently active branch
set automatic command line coloring for Git for easy reviewing
git branch [branch-name]

create a new branch at the current commit

SETUP & INIT git checkout


Configuring user information, initializing and cloning repositories
switch to another branch and check it out into your working directory
git init git merge [branch]

initialize an existing directory as a Git repository merge the specified branch’s history into the current one
git clone [url] git log

retrieve an entire repository from a hosted location via URL show all commits in the current branch’s history
INSPECT & COMPARE SHARE & UPDATE
Examining logs, diffs and object information Retrieving updates from another repository and updating local repos

git log git remote add [alias] [url]

show the commit history for the currently active branch add a git URL as an alias
git log branchB..branchA git fetch [alias]

show the commits on branchA that are not on branchB fetch down all the branches from that Git remote
git log --follow [file] git merge [alias]/[branch]

show the commits that changed file, even across renames merge a remote branch into your current branch to bring it up to date
git diff branchB...branchA git push [alias] [branch]

show the diff of what is in branchA that is not in branchB Transmit local branch commits to the remote repository branch
git show [SHA] git pull

show any object in Git in human-readable format fetch and merge any commits from the tracking remote branch

TRACKING PATH CHANGES REWRITE HISTORY


Versioning file removes and path changes Rewriting branches, updating commits and clearing history

git rm [file] git rebase [branch]

delete the file from project and stage the removal for commit apply any commits of current branch ahead of specified one

git mv [existing-path] [new-path] git reset --hard [commit]

change an existing file path and stage the move clear staging area, rewrite working tree from specified commit

git log --stat -M

show all commit logs with indication of any paths that moved TEMPORARY COMMITS
Temporarily store modified, tracked files in order to change branches

IGNORING PATTERNS git stash


Preventing unintentional staging or commiting of files Save modified and staged changes

logs/ git stash list


*.notes
pattern*/ list stack-order of stashed file changes
git stash pop
Save a file with desired patterns as .gitignore with either direct string
matches or wildcard globs. write working from top of stash stack
git config --global [Link] [file] git stash drop

system wide ignore pattern for all local repositories discard the changes from top of stash stack

Education
Teach and learn better, together. GitHub is free for students and teach- education@[Link]
ers. Discounts available for other educational uses. [Link]
GIT CHEAT SHEET

Git is the free and open source distributed version control system that's responsible for everything GitHub
related that happens locally on your computer. This cheat sheet features the most important and commonly
used Git commands for easy reference.

INSTALLATION & GUIS STAGE & SNAPSHOT


With platform specific installers for Git, GitHub also provides the Working with snapshots and the Git staging area
ease of staying up-to-date with the latest releases of the command
line tool while providing a graphical user interface for day-to-day git status
interaction, review, and repository synchronization.
show modified files in working directory, staged for your next commit
GitHub for Windows
git add [file]
[Link]
add a file as it looks now to your next commit (stage)
GitHub for Mac
[Link] git reset [file]

unstage a file while retaining the changes in working directory


For Linux and Solaris platforms, the latest release is available on
the official Git web site. git diff

Git for All Platforms diff of what is changed but not staged
[Link]
git diff --staged

diff of what is staged but not yet committed

SETUP git commit -m “[descriptive message]”


Configuring user information used across all local repositories commit your staged content as a new commit snapshot

git config --global [Link] “[firstname lastname]”

set a name that is identifiable for credit when review version history
git config --global [Link] “[valid-email]”
BRANCH & MERGE
Isolating work in branches, changing context, and integrating changes
set an email address that will be associated with each history marker
git branch
git config --global [Link] auto
list your branches. a * will appear next to the currently active branch
set automatic command line coloring for Git for easy reviewing
git branch [branch-name]

create a new branch at the current commit

SETUP & INIT git checkout


Configuring user information, initializing and cloning repositories
switch to another branch and check it out into your working directory
git init git merge [branch]

initialize an existing directory as a Git repository merge the specified branch’s history into the current one
git clone [url] git log

retrieve an entire repository from a hosted location via URL show all commits in the current branch’s history
INSPECT & COMPARE SHARE & UPDATE
Examining logs, diffs and object information Retrieving updates from another repository and updating local repos

git log git remote add [alias] [url]

show the commit history for the currently active branch add a git URL as an alias
git log branchB..branchA git fetch [alias]

show the commits on branchA that are not on branchB fetch down all the branches from that Git remote
git log --follow [file] git merge [alias]/[branch]

show the commits that changed file, even across renames merge a remote branch into your current branch to bring it up to date
git diff branchB...branchA git push [alias] [branch]

show the diff of what is in branchA that is not in branchB Transmit local branch commits to the remote repository branch
git show [SHA] git pull

show any object in Git in human-readable format fetch and merge any commits from the tracking remote branch

TRACKING PATH CHANGES REWRITE HISTORY


Versioning file removes and path changes Rewriting branches, updating commits and clearing history

git rm [file] git rebase [branch]

delete the file from project and stage the removal for commit apply any commits of current branch ahead of specified one

git mv [existing-path] [new-path] git reset --hard [commit]

change an existing file path and stage the move clear staging area, rewrite working tree from specified commit

git log --stat -M

show all commit logs with indication of any paths that moved TEMPORARY COMMITS
Temporarily store modified, tracked files in order to change branches

IGNORING PATTERNS git stash


Preventing unintentional staging or commiting of files Save modified and staged changes

logs/ git stash list


*.notes
pattern*/ list stack-order of stashed file changes
git stash pop
Save a file with desired patterns as .gitignore with either direct string
matches or wildcard globs. write working from top of stash stack
git config --global [Link] [file] git stash drop

system wide ignore pattern for all local repositories discard the changes from top of stash stack

Education
Teach and learn better, together. GitHub is free for students and teach- education@[Link]
ers. Discounts available for other educational uses. [Link]
Git - 0 to Pro Reference
By: [Link]
Tutorial link: [Link]

Command Line (Terminal / PowerShell)


ls List the files and folders in the current folder
cd ~/Desktop/folder Change the folder that the command line is
running in

Note: git commands must be run inside the folder that contains all the code.

Creating Commits
In Git, version = commit
Version history = commit history

git init Git will start tracking all changes in the current folder
git status Show all changes since the previous commit

git add <file|folder> Pick changes to go into next commit


git add file Pick individual file
git add folder/ Pick all files inside a folder (and subfolders)
git add . Pick all files (in folder command line is running in)

git commit -m "message" Creates a commit with a message attached


git commit -m "message" --amend Update previous commit instead of creating new one

git log View the commit history


git log --all Show all commits (not just current branch)
git log --all --graph Show branching visually in the command line

Configure Name & Email for Commits


git config --global [Link] "Your Name"
git config --global [Link] "email@[Link]"

Working Area = contains changes start in the working area


Staging Area = contains changes that will go into the next commit
git add . working => staging
git commit -m "message" staging => commit history

git reset <file|folder> staging => working


git reset file
git reset folder/
git reset .
git checkout -- <file|folder> working => remove the changes
git checkout -- file
git checkout -- folder/
git checkout -- .

Viewing Previous Commits


git checkout <commit_hash|branch_name> View a previous commit

master = branch name


1. You can git checkout branch
2. Always points to latest commit
on the branch.

HEAD = indicates which commit


you are currently viewing

Restoring to a Previous Commit


git checkout <hash|branch> <file|folder> Restore the contents of files back to a
previous commit
git checkout <hash|branch> file Restore a file
git checkout <hash|branch> folder/ Restore all files in folder (& subfolders)
git checkout <hash|branch> . Restore all files in project

Other Features of Git


git config --global [Link] <command> Creates an alias (a shortcut)
git config --global alias.s "status" git s = git status
.gitignore Tell git which files/folders it SHOULD NOT track
rm -rf .git Remove git from project

GitHub
Repository = a folder containing code where any changes to the code are tracked by git.
(To create a repository, we create a new folder on our computer, and then run git init)

GitHub = a service that lets us save our git repositories online. It also helps us:
- backup our code in case we delete it on our computer
- see the history of our code changes more easily
- alternatives include Bitbucket and GitLab

Local repository = a git repository saved on our computer


Remote repository = a git repository saved online (for example on GitHub)

Uploading Code to GitHub


git remote add <remote_name> <url> Link a local repository to a remote repository and
give a name for this link

git remote add origin [Link]


^
The above command links a local repository to a GitHub repository (located at the url
[Link] and gives it a name "origin"

git remote List all remote repositories that are linked


git remote -v List all remote repositories (but with more detail)

git remote remove <remote_name> Removes a link to a remote repository


git remote remove origin Removes the link to the remote repository named
"origin"

git config --global [Link] <username>


Configure your GitHub username so you can get
access to your Github repository

git push <remote_name> <branch> Upload a branch of your git version history to your
remote repository

git branch Shows a list of available branches


git log --all --graph Shows the branches visually in the history
git push origin main Upload the branch "main" to the remote repository
named "origin"
git push <remote_name> <branch> --set-upstream Sets up a shortcut for this
branch and remote repository
git push origin main --set-upstream Next time you are on the main
branch and you run git push, it
will automatically push the
main branch to origin

git push <remote_name> <branch> -f Force-push the branch to the remote repository (it
will overwrite what's on the remote repository)

Downloading Code from GitHub


git clone <url> Download a remote repository from a url
git clone [Link]

git clone <url> <folder_name> Download the repository and give it a different
folder name

git fetch Updates all remote tracking branches. Remote


tracking branches (like origin/main) show what
the branch looks like in the remote repository

git pull <remote_name> <branch> Update the local branch with any updates from
the remote repository (on GitHub)
git pull origin main Downloads any new commits from the main
branch on origin, and updates the local main
branch with those new commits
git pull origin main --set-upstream
^
Sets up a shortcut so that the next time you are on the main branch and run git pull, it will
automatically git pull origin main

Branching
Branching = create a copy of the version history that we can work on without affecting the
original version history. This lets us work on multiple things (features + fixes) at the same time.

git branch <branch_name> Creates a new branch


git branch feature1 Create a new branch named feature1

git checkout <branch_name> Switch to a different branch and start working on


that branch
git checkout feature1 Switch to the feature1 branch. New commits will
now be added to the feature1 branch
HEAD = points to which branch we are currently working on
HEAD -> feature1 = we are currently working on the feature1 branch. Any new commits will
be added to the feature1 branch

git branch -D <branch_name> Deletes a branch


git branch -D feature1 Deletes the feature1 branch

Merging
git merge <branch_name> -m "message" Merge the current branch (indicated by HEAD ->)
with another branch (<branch_name>). Saves
the result of the merge as a commit on the
current branch

git checkout main 1. First switch to the main branch


git merge feature1 -m "message" 2. Then merge the main branch with the
feature1 branch. The result of the merge will be
added to main as a commit (a "merge commit")

Merge Conflicts
<<<<<<< HEAD If there is a merge conflict (git doesn't know
code1 what the final code should be), it will add this in
======= your code.
code2
>>>>>>> branch (This is just for your convenience, the <<<<<<<
and >>>>>>> don't have special meaning)
<<<<<<< HEAD
... <-- Code in the current branch (indicated by HEAD ->)
=======
... <-- Code in the branch that is being merged into HEAD
>>>>>>> branch

To resolve a merge conflict:

1. Delete all the extra code and just leave the final code that you want.
<<<<<<< HEAD
code1
======= => code2
code2
>>>>>>> branch

2. If there are conflicts in multiple places in your code, repeat step 1 for all those places.

3. Create a commit.
git add .
git commit -m "message"

Feature Branch Workflow


A popular process that companies use when adding new features to their software.

1. Create a branch for the new feature (called a "feature branch").


git branch new-feature
git checkout new-feature
Make some changes to the code...
git add .
git commit -m "new feature message"

2. Upload the feature branch to GitHub.


git push origin new-feature

3. Create a pull request on GitHub (a pull request lets teammates do code reviews and add
comments).
4. Merge the feature branch into the main branch (by opening the pull request in the browser
and clicking "Merge pull request")

5. After merging, update the local repository (so that it stays in sync with the remote repository
on GitHub).
git checkout main
git pull origin main

Merge Conflicts in the Feature Branch Workflow


A merge conflict can happen if 2 or more pull requests change the same file and the same line.

We can either:
1. Resolve the merge conflict on GitHub.

2. Resolve the merge conflict on our computer.


1) Get the latest updates from main
git checkout main
git pull origin main

2) Get the latest updates from the feature branch.


git checkout feature4
git pull origin feature4

3) Merge main into the feature branch (feature4). Notice the direction of the merge: we want
the merge commit to stay on the feature branch so our teammates can review it.
git checkout feature4
git merge master

4) Push the resolved feature branch to GitHub.


git push origin feature4

Now the pull request should be ready to merge again.


GitHub Pages Reference
By: [Link]
Video Tutorial: [Link]

GitHub Pages
Lets us put websites created with HTML, CSS, and JavaScript code on the Internet

Overall Process
1. Write your HTML, CSS, and JavaScript code on your computer (as normal)
2. Upload your code to a GitHub repository
3. Turn on GitHub Pages from the repository's settings
That's it!

Step By Step
1. Write the code for your website as normal (make sure your website works when you open the
HTML file in your browser)
2. In your browser, go to "[Link]" and sign in

3. Click your icon in the top-right > Click "Your repositories"


(repository = folder that contains all your code)

4. If you already have a repository, open it. Otherwise, on the right side click "New"
4a. When creating a new repository:
● Give it a name (any name is fine)
● Make sure it is "Public" (private repositories need to pay a fee to use GitHub Pages)
● Everything else can be left as default

Upload Your Code


5. Click "Upload files"

New repository: Existing repository:

You can also add "/upload" to the end of the URL:

6. Drag and drop the code you want to upload and click "Commit Changes" at the bottom.
❌ Don't drag the folder containing all your code into GitHub
✅ First open the folder, then select all your code and drag and drop into GitHub

Turn on GitHub Pages


7. In your repository, click "Settings" on the top-right.

8. Click the "Pages" tab on the left.


9. Select Branch: main (or master) and click Save.

10. To visit your GitHub Pages website, enter this URL at the top of your browser:
[your_github_username].[Link]/[repository_name]/[file_name].html

If you don't provide an HTML file, GitHub Pages will look for a file called "[Link]":
[your_github_username].[Link]/[repository_name]

Set up a Domain Name


1. Purchase a domain from a domain registrar (Namecheap, [Link], Google Domains, etc.)

2. We'll link our domain name to GitHub Pages' IP address. Here's the diagram for reference

IP Address
● Is like a phone number (but for the Internet)
● Any device that connects to the Internet is given an IP address. At home, you connect to the
Internet through a router. In this case, only the router will get an IP address that is public
● A device can communicate with another device across the Internet using an IP address
IPv4 example: [Link]
IPv6 example: [Link]

3. Find GitHub Pages IP address. Go to [Link] and search for


"[your_github_username].[Link]"

Create DNS Records


DNS records let us link IP addresses (and other information) to a domain name.

4. Log into your domain registrar > open the "Settings" for your domain.
If you're not using Namecheap, see [Link]
In Namecheap:
● Go to your Dashboard > click "Domain List" on the left
● Find your domain > click "Manage" on the right > click "Advanced DNS"
● Look for this table (that lets us create DNS records):

5. Create an A Record = links a domain name to an IP address

● 1st value, select "A Record"


● 2nd value is the subdomain, which is the part of a URL in front of a domain name (like
[Link]). Namecheap, use "@". Other domain registrars, leave it blank
● 3rd value, enter an IP address found in step 3
● 4th value is TTL = time to live (how long DNS records will live before being refreshed).
Namecheap, select "5 min". Other domain registrars, enter "300" (300 seconds)

Create a DNS A Record for each IP address from step 3. Here's the end result:
6. Create a CNAME Record = links a domain name to another domain name.
Set up the subdomain "www" ([Link]). This is recommended by GitHub Pages.

● 1st value, select "CNAME Record"


● 2nd value, enter "www"
● 3rd value, enter your GitHub Pages domain name = [your_github_username].[Link]
● 4th value, enter "5 min" or "300"

Here's the end result:

Summary
A Record = [Link] -> ip address
CNAME Record = [Link] -> domain name

Note
A CNAME Record can only be used when there is a subdomain. Some registrars offer an ALIAS
Record which can link the base domain name ("[Link]") to another domain.
Set up Domain Name in GitHub Pages
1. Go to the GitHub repository for your website

2. Click "Settings" on the right > click "Pages" on the left

3. In the "Custom domain" section, enter your domain name. Click Save

4. Wait for GitHub's process to finish. Then check the box to activate HTTPS

HTTPS encrypts all data flowing between your browser and your website.

5. Finally visit your website by entering in the top of your browser:

You might also like