Having a Git
and GitHub
cheat sheet is highly beneficial, especially for those who frequently utilize these tools but may not remember every command. Git commands are crucial as they allow us to perform tasks like creating new repositories, making changes to existing projects, and viewing the history of our changes.
This cheat sheet is a handy reference guide for both beginners and experienced users. For beginners, it provides a simple and quick way to learn and use the most common commands. For experienced users, it serves as a quick reference for less frequently used commands or options. By having all the essential Git and GitHub commands in one place, productivity can be improved and common tasks can be performed faster π.
Git Configurations
# Sets up Git with your namegit config --global user.name "<Your-Full-Name>"
# Sets up Git with your emailgit config --global user.email "<your-email-address>"
# Sign all commits by defaultgit config --global commit.gpgsign true
# Globally disables fast-forward merging by defaultgit config --global merge.ff false
# Makes sure that Git output is coloredgit config --global color.ui auto
# Displays the original state in a conflictgit config --global merge.conflictstyle diff3
# Configure text editorgit config --global core.editor "[code, atom, vim , nano, gedit] --wait"
# List all your configurationsgit config --list
Git Startup Commands
# Create brand new repositories (repos) on your computer.git init
# Copy existing repos from somewhere else to your local computer.git clone {Repo URL}
# Check the status of a repogit status
Git Log
# Display information about the existing commits.git log
# Display commits per one line.git log --oneline
# Display the files that have been changed in the commit.git log --stat
# display the actual changes made to a file.git log -p
# display the actual changes made to a commit.git log -p {commit id}# Orgit show {commit id}
Git Add & Commit
# Add files from the working directory to the staging index.git add
# add filesgit add {file1} {file2} ...
# Add all files in the current directorygit add .
# Take files from the staging index and save them in the repository.git commit
# Displays the difference between two versions of a file.git diff
Refresh gitignore
# Unstage all filesgit rm -r --cached .
# Add them back in so that, the new .gitignore files will work.git add .
Git Tag
# Add a signed taggit tag -s v1.0
# Display all tagsgit tag
# Delete a tag locallygit tag -d v1.0
# Delete a tag from the remotegit push --delete origin v1.0
# Adding a tag to a past commitgit tag -a v1.0 {commit id}
Git Branch
# List all branch names in the repository.git branch
# Create new branch named sidebar.git branch sidebar
# Change current branch to sidebar.git checkout sidebar
# Create the alt-sidebar-loc branch and have it point to the commit with SHA 42a69f.git branch alt-sidebar-loc 42a69f
# Delete a branch.git branch -d sidebar
# Force delete a branch.git branch -D sidebar
# see all branches' history at once.git log --oneline --decorate --graph --all
# Create a branch and then checkout to the new branch.git checkout -b fix-footer
Git Merge
# Merge sidebar into current branch without fast forwarding merge.git merge --no-ff sidebar
Git Revert & Reset
# Alter the most-recent commit or add missing filesgit commit --amend
# Reverses given commitgit revert {commit-id}
# Erases commitsgit resetgit reset [tags] HEAD~1tags:--mix -> move commit to working directory--soft -> move commit to staged index--hard -> move commit to trash
GitHub
# Display full path to the remote repository.git remote -v
# Create a connection from local repository to the remote repository.git remote add origin {repository link}
# Send changes to the remotegit push
# Retrieve updates from the remotegit pull
Thatβs all for this Git and GitHub cheat sheet! Keep this guide handy for quick reference while working on your projects. Remember, practice makes perfect, so keep using these commands until they become second nature. Happy coding! π¨βπ»π©βπ»