Catalog / Version Control Cheatsheet
Version Control Cheatsheet
A comprehensive cheat sheet covering essential version control concepts, commands, and workflows with Git.
Git Basics
Core Concepts
Repository: A directory containing project files and a |
Working Directory: The directory on your file system containing the actual files you are working on. This is where you make changes. |
Staging Area (Index): A file that stores information about the changes you want to include in your next commit. Use |
Commit: A snapshot of your repository at a specific point in time. Commits have a unique ID (SHA-1 hash). |
Branch: A movable pointer to a commit. Branches allow you to work on different features or fixes without affecting the main codebase. |
Remote: A repository hosted on another computer or server. Used for collaboration and backups. |
Basic Commands
|
Initializes a new Git repository in the current directory. |
|
Clones a remote repository to your local machine. |
|
Displays the status of the working directory and staging area. |
|
Adds a file to the staging area. |
|
Commits the staged changes with a descriptive message. |
|
Shows the commit history of the repository. |
Branching and Merging
Branch Management
|
Lists all local branches. The current branch is marked with an asterisk (*). |
|
Creates a new branch with the specified name. |
|
Switches to the specified branch. |
|
Creates a new branch and switches to it. |
|
Deletes the specified branch (if it has been merged). |
|
Force deletes the specified branch (even if it hasn’t been merged). |
Merging Branches
|
Merges the specified branch into the current branch. |
|
Opens a merge tool to resolve conflicts manually. |
|
After resolving conflicts, commit the merge. |
|
Aborts the merge process and returns to the state before the merge. |
Rebasing
Rebasing is an alternative to merging that integrates changes from one branch into another by moving or combining a sequence of commits to a new base commit. |
|
After resolving conflicts, use |
Use |
Remote Repositories
Working with Remotes
|
Adds a remote repository with a specified name and URL. |
|
Lists all remote repositories with their URLs. |
|
Removes the remote repository with the specified name. |
|
Fetches the latest changes from the remote repository without merging them. |
|
Fetches and merges changes from a remote branch into the current branch. |
|
Pushes local commits to the remote branch. |
Collaboration Workflow
|
|
|
|
|
|
Advanced Git
Stashing
|
Temporarily saves changes that you don’t want to commit immediately. |
|
Lists all stashed changesets. |
|
Applies the most recent stashed changes. |
|
Applies a specific stashed changeset (e.g., the third one). |
|
Removes the most recent stashed changes. |
|
Applies and removes the most recent stashed changes. |
Rewriting History
Warning: Rewriting history can cause issues if you’re collaborating with others. Use with caution. |
|
|
Ignoring Files
|
A file that specifies intentionally untracked files that Git should ignore. |
Example |
|