Welcome to the Git Cheatsheet Repository. This repository is created to support the Git Version Control for Beginners CodeSignal Course Path, designed to help learners master Git fundamentals and advanced workflows.
CodeSignal is a leading platform for technical skill assessment and development. It offers a variety of courses, challenges, and learning paths that help individuals improve their technical skills across domains like programming, DevOps, and data science.
The Git Course Path focuses on building practical knowledge of Git for real-world software development. The course covers a variety of topics, starting from basic Git commands to mastering working with remote repositories.
For more information about this course, visit this link.
This repository is your companion to the Git Course Path and serves as a quick reference for essential Git commands. It's designed to help you:
- Quickly recall frequently used commands.
- Reinforce your learning through a structured cheatsheet.
Whether you're starting with Git or looking to solidify your knowledge, this cheatsheet provides an organized view of the most important commands.
- Getting Started with Git
- Tracking and Managing Changes
- Branching and Collaboration
- Undoing and Modifying Changes
- Exploring and Comparing
- Ignoring Files
- Stashing Changes
These commands configure your identity and preferences:
git config --global user.name "[Your Name]"
Set your username for commits.git config --global user.email "[Your Email]"
Set your email address for commits.git config --list
Display your current Git configuration.
git init
Turn a folder into a Git repository.git clone [url]
Copy an existing repository to your local machine.
Prepare and save your changes with these commands:
git status
View the status of your working directory and staged files.git add [file]
Stage specific changes.git add .
Stage all changes in the current directory.git commit -m "[message]"
Create a commit with a message describing the changes.git commit --amend
Modify the most recent commit (e.g., to fix a message).
git restore [file]
Discard changes in a file (unstaged).git restore --staged [file]
Unstage changes while keeping them in your working directory.
Branches allow parallel development:
git branch
List all branches.git branch [branch-name]
Create a new branch.git switch [branch-name]
Switch to a different branch.git branch -d [branch-name]
Delete a branch.
Collaborate with others using remote repositories:
git remote add origin [url]
Add a remote repository to your project.git push -u origin [branch-name]
Push changes to a remote branch and track it.git fetch origin
Download updates from the remote repository without merging them into your current branch.git pull origin [branch-name]
Fetch and merge changes from a remote branch.
These commands help you modify commit history carefully:
git revert [commit-hash]
Create a new commit that undoes changes from a specific commit.git reset --soft [commit]
Move the HEAD pointer but keep staged changes.git reset --hard [commit]
Undo commits and discard all uncommitted changes.
Understand what has changed with these commands:
-
git log --oneline
Display a compact commit history. -
git diff
Compare unstaged changes with the most recent commit. -
git diff [branch-name]
Compare your current branch with another branch. -
git diff commit1..commit2
Compare changes between two commits. -
git diff branch1..branch2
Compare the differences between two branches. -
git show [commit-hash]
Show the details of a specific commit.
Control which files Git should ignore:
- Save patterns in
.gitignore
:# Ignore compiled files *.o *.class
Stash allows you to save your changes without committing:
git stash
Temporarily store your uncommitted changes.git stash apply
Apply the most recent stash without removing it.git stash drop
Delete the most recent stash.git stash clear
Remove all stashes from your repository.