└── README.md /README.md: -------------------------------------------------------------------------------- 1 | ## Welcome 2 | 3 |

4 | Welcome to the Git Cheat sheet Repository. This repository is created to support the Git Version Control for Beginners CodeSignal Course Path, designed to help learners master Git fundamentals and advanced workflows. Cosmo 5 |

6 | 7 | ## About CodeSignal 8 | 9 | **CodeSignal Learn** is a platform for skill assessment and development. It offers a variety of courses, challenges, and learning paths that help individuals improve their technical skills in areas like programming and data science, enhance soft skills and sales expertise, and prepare effectively for interviews. 10 | 11 | The **Git Version Control for Beginners** course path focuses on building practical knowledge of Git for real-world software development. The course path covers a variety of topics, starting from basic Git commands to mastering working with remote repositories. 12 | 13 | For more information about this course path, visit this [link](https://learn.codesignal.com/preview/course-paths/140). 14 | 15 | 16 | ## About This Repository 17 | 18 | This repository is your **companion to the Git Course Path** and serves as a quick reference for essential Git commands. It's designed to help you: 19 | - Quickly recall **frequently used commands**. 20 | - Reinforce your learning through a **structured cheat sheet**. 21 | 22 | Whether you're starting with Git or looking to 23 | solidify your knowledge, this cheat sheet provides an organized view of the most important commands. 24 | 25 | --- 26 | 27 | ## Table of Contents 28 | - [Getting Started with Git](#getting-started-with-git) 29 | - [Tracking and Managing Changes](#tracking-and-managing-changes) 30 | - [Branching and Collaboration](#branching-and-collaboration) 31 | - [Undoing and Modifying Changes](#undoing-and-modifying-changes) 32 | - [Exploring and Comparing](#exploring-and-comparing) 33 | - [Ignoring Files](#ignoring-files) 34 | - [Stashing Changes](#stashing-changes) 35 | 36 | --- 37 | 38 | ## Getting Started with Git 39 | 40 | ### Setting Up Your Environment 41 | 42 | These commands configure your identity and preferences: 43 | 44 | - `git config --global user.name "[Your Name]"` 45 | Set your username for commits. 46 | - `git config --global user.email "[Your Email]"` 47 | Set your email address for commits. 48 | - `git config --list` 49 | Display your current Git configuration. 50 | 51 | ### Starting a Repository 52 | - `git init` 53 | Turn a folder into a Git repository. 54 | - `git clone [url]` 55 | Copy an existing repository to your local machine. 56 | 57 | --- 58 | 59 | ## Tracking and Managing Changes 60 | 61 | ### Staging and Committing Changes 62 | 63 | Prepare and save your changes with these commands: 64 | 65 | - `git status` 66 | View the status of your working directory and staged files. 67 | - `git add [file]` 68 | Stage specific changes. 69 | - `git add .` 70 | Stage all changes in the current directory. 71 | - `git commit -m "[message]"` 72 | Create a commit with a message describing the changes. 73 | - `git commit --amend` 74 | Modify the most recent commit (e.g., to fix a message). 75 | 76 | ### Removing or Unstaging Changes 77 | - `git restore [file]` 78 | Discard changes in a file (unstaged). 79 | - `git restore --staged [file]` 80 | Unstage changes while keeping them in your working directory. 81 | 82 | --- 83 | 84 | ## Branching and Collaboration 85 | 86 | ### Working with Branches 87 | 88 | Branches allow parallel development: 89 | - `git branch` 90 | List all branches. 91 | - `git branch -r` 92 | List all remote branches. 93 | - `git branch [branch-name]` 94 | Create a new branch. 95 | - `git switch [branch-name]` 96 | Switch to a different branch. 97 | - `git checkout [branch-name]` 98 | Switch to a specific branch. 99 | - `git checkout -b [branch-name]` 100 | Create a new branch and switch to it in one step. 101 | - `git switch -c [branch-name]` 102 | Create a new branch and switch to it. 103 | - `git branch -d [branch-name]` 104 | Delete a branch. 105 | - `git branch -D [branch-name]` 106 | Force delete a branch. 107 | - `git branch -m [new-branch-name]` 108 | Rename the current branch. 109 | 110 | ### Merging and Applying Changes 111 | Combine changes from branches or commits into your current branch to integrate updates. 112 | - `git cherry-pick [commit-hash]` 113 | Apply changes from a specific commit to the current branch. 114 | - `git merge [branch-name]` 115 | Merge the specified branch into the current branch. 116 | - `git rebase [branch-name]` 117 | Reapply commits from the current branch onto the specified branch to maintain a linear history. 118 | - `git rebase --continue` 119 | Resume an interrupted rebase after resolving conflicts. 120 | - `git rebase -i HEAD~N` 121 | Start an interactive rebase for the last N commits, allowing you to edit, reorder, squash, or drop commits. 122 | ### Pushing and Pulling Changes 123 | 124 | Collaborate with others using remote repositories: 125 | - `git remote add origin [url]` 126 | Add a remote repository to your project. 127 | - `git push origin [branch-name]` 128 | Push local changes from the specified branch to a remote repository. 129 | - `git push -u origin [branch-name]` 130 | Push changes to a remote branch and track it. 131 | - `git fetch origin` 132 | Download updates from the remote repository without merging them into your current branch. 133 | - `git pull origin [branch-name]` 134 | Fetch and merge changes from a remote branch. 135 | --- 136 | 137 | ## Undoing and Modifying Changes 138 | 139 | ### Reverting or Resetting Commits 140 | 141 | These commands help you modify commit history carefully: 142 | - `git revert [commit-hash]` 143 | Create a new commit that undoes changes from a specific commit. 144 | - `git reset --soft [commit]` 145 | Move the HEAD pointer but keep staged changes. 146 | - `git reset --hard [commit]` 147 | Undo commits and discard all uncommitted changes. 148 | 149 | --- 150 | 151 | ## **Exploring and Comparing** 152 | 153 | ### **Viewing Logs and Diffs** 154 | 155 | Understand and analyze changes in your repository with these commands: 156 | 157 | - `git log --oneline` 158 | Display a compact commit history. 159 | 160 | - `git diff` 161 | Compare unstaged changes with the most recent commit. 162 | 163 | - `git diff [branch-name]` 164 | Compare your current branch with another branch. 165 | 166 | - `git diff commit1..commit2` 167 | Compare changes between two commits. 168 | 169 | - `git diff branch1..branch2` 170 | Compare the differences between two branches. 171 | 172 | - `git diff --staged` 173 | Show differences between staged changes and the last commit. 174 | 175 | - `git diff --cached` 176 | Show differences between staged changes and the last commit (same as `--staged`). 177 | 178 | - `git show [commit-hash]` 179 | Show the details of a specific commit. 180 | 181 | - `git reflog` 182 | Show a log of all reference updates (e.g., branch checkouts, commits, resets, and rebases). 183 | 184 | ### **Working with Tags** 185 | 186 | Use tags to mark important commits: 187 | 188 | - `git tag [tag-name]` 189 | Create a lightweight tag for the current commit. 190 | 191 | - `git tag -l` 192 | List all tags in the repository. 193 | 194 | - `git tag -a [tag-name] -m "[message]"` 195 | Create an annotated tag with a message for the current commit. 196 | 197 | - `git tag -d [tag-name]` 198 | Delete a tag locally. 199 | 200 | --- 201 | 202 | ## Ignoring Files 203 | 204 | ### Using `.gitignore` 205 | 206 | Control which files Git should ignore: 207 | - Save patterns in `.gitignore`: 208 | ```plaintext 209 | # Ignore compiled files 210 | *.o 211 | *.class 212 | ``` 213 | 214 | --- 215 | 216 | ## Stashing Changes 217 | 218 | ### Temporarily Saving Progress 219 | 220 | Stash allows you to save your changes without committing: 221 | - `git stash` 222 | Temporarily store your uncommitted changes. 223 | - `git stash apply` 224 | Apply the most recent stash without removing it. 225 | - `git stash drop` 226 | Delete the most recent stash. 227 | - `git stash clear` 228 | Remove all stashes from your repository. 229 | - `git stash -u` 230 | Stash tracked and untracked changes. 231 | - `git stash list` 232 | Show saved stashes. 233 | --- 234 | --------------------------------------------------------------------------------