Skip to content

GitCheat Sheet for a DevOps Engineer

  • by

In DevOps, Git reigns supreme as the version control system of choice. It empowers you to track changes, collaborate seamlessly, and troubleshoot easily. But with a plethora of commands, navigating Git can seem daunting. Fear not, DevOps engineers! This guide unveils the essential Git commands you need to conquer common issues and become a version control hero.

Git Architecture

Unlike its predecessors, Git isn’t just about file changes; it captures snapshots of your entire project filesystem. This unique approach makes Git lightning-fast and incredibly efficient, storing unique data and referencing existing files when possible.

Basic Git Commands

  • git init: Initialize a new Git repository in your project directory.
  • git clone: Create a local copy of a remote Git repository.
  • git add: Add specific files to the staging area for the next commit.
  • git status: See which files are modified, staged, or untracked.
  • git commit -m “message”: Commit your staged changes with a meaningful message.
  • git commit –amend: Modify the most recent commit message.
  • git fetch: Download data from remote repositories without merging.
  • git pull: Fetch and merge changes from a remote repository.
  • git push: Upload your local changes to a remote repository.
  • git push origin master: Push your changes to the remote “master” branch.
  • git remote show origin: Display details about the “origin” remote repository.
  • .gitignore: Specify files or patterns to exclude from version control.
  • git diff: Compare files between different versions or branches.
  • git rm: Remove files from your project and staging area.
  • git mv: Rename files and update the Git index.
  • git log: View the history of commits in your repository.
  • git restore: Recover deleted or modified files.
  • git remote -v: List all configured remote repositories and their URLs.
  • git tag: Create or list tags, which are bookmarks pointing to specific commits.
  • git tag -a v1.2 9fceb02: Tag commit “9fceb02” with the name “v1.2”.
  • git branches: List all local branches.
  • git merge tool: Use a graphical tool to resolve merge conflicts.
  • git branch -v: List all local branches with their latest commit hash and status.

Advanced GIT Commands

While the basic Git commands empower you to navigate changes and collaborate effectively, true mastery lies in venturing into advanced commands. These unlock potent functionalities, allowing you to fine-tune your workflow, resolve complex issues, and delve deeper into your project’s history.

So, strap on your climbing gear, fellow Git enthusiasts, and prepare to scale the heights of version control expertise!

Branching and Merging Mastery:

  • git rebase: Rewrite branches onto another branch’s history, creating a cleaner linear history.
  • git cherry-pick: Select specific commits from one branch and apply them to another.
  • git stash: Temporarily save uncommitted changes to apply later.
  • git submodule: Manage external code repositories within your project.

Refactoring and Undoing:

  • git revert: Revert specific commit(s) without rewriting history.
  • git reset: Rewind your working directory or staging area to a specific state.
  • git amend: Modify the most recent commit message and optionally contents.
  • git blame: Show who last modified each line of a file.

Debugging and Troubleshooting:

  • git bisect: Isolate the commit that introduced a bug using a binary search.
  • git reflog: View the history of Git commands executed in your repository.
  • git fsck: Check and repair Git repository data integrity issues.

Unveiling the Depths:

  • git gc: Collect and reclaim unused Git objects for storage optimization.
  • git hooks: Create custom scripts to automate tasks before or after specific Git events.
  • git config: Configure Git settings for your specific workflow and preferences.