Day 13: Git Cheat Sheet
|
Nov 5, 2024
•01:13 AM GMT+8
A powerful version control tool, Git offers essential tools for tracking, sharing, and managing code. Here is a cheat sheet you can use as a quick reference.
Git Setup
Command | Description |
git config --global user.name "[username]" | Configure your username for all repositories on your system. |
git config --global user.email "[valid-email]" | Configure your email for all repositories on your system. |
git init | Start a new Git repository in your current directory. |
git clone [url] | Copy an existing remote repository to your local system. |
Git Staging
Command | Description |
git status | View changes in your working directory, including staged and unstaged files. |
git add [file] | Add a file to the staging area, preparing it for a commit. |
git commit -m "[message]" | Save staged changes with a descriptive message. |
Git Resetting Changes
Command | Description |
git reset --soft [commit] | Move the HEAD to a previous commit, retaining changes in the staging area. |
git reset --hard [commit] | Reset to a previous commit, discarding all subsequent changes. |
Git Branching and Merging
Command | Description |
git branch | View all branches in your repository and highlight the current branch. |
git branch [branch-name] | Start a new branch for development. |
git checkout [branch-name] / git switch [branch-name] | Move to a different branch. |
git merge [branch-name] | Integrate changes from the specified branch into the current branch. |
Git Inspecting and Comparing
Command | Description |
git log | See a list of previous commits. |
git log [branch-B] [branch-A] | View commits on branch A that are not in branch B. |
git diff [branch-B] [branch-A] | Compare changes between two branches. |
Git Updating and Pushing Changes
Command | Description |
git fetch | Retrieve updates from a remote repository without merging. |
git push | Send local changes to a remote repository. |
git pull | Download and merge changes from a remote repository into your current branch. |
Git Ignoring Files
Command | Description |
.gitignore | Specify files and patterns Git should ignore (e.g., *.log to ignore log files). |
Conclusion
In this Git cheat sheet, you'll find a comprehensive list of the most important Git commands. In the next post, we'll discuss Python Fundamentals, one of the most essential skills for DevOps.
Share
Day 13: Git Cheat Sheet
Make your daily DevOps workflow easier and more efficient with this comprehensive cheat sheet of essential Git commands
For the passion of automated cloud solutions.
Subscribe to get the latest posts. I mostly write about Backend (Python/Bash), DevOps and Linux.