Day 13: Git Cheat Sheet

Adrian Rubico

|

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

CommandDescription
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 initStart a new Git repository in your current directory.
git clone [url]Copy an existing remote repository to your local system.

Git Staging

CommandDescription
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

CommandDescription
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

CommandDescription
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

CommandDescription
git logSee 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

CommandDescription
git fetch    Retrieve updates from a remote repository without merging.
git pushSend local changes to a remote repository.
git pullDownload and merge changes from a remote repository into your current branch.

Git Ignoring Files

CommandDescription
.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.

Discussion