├── .gitignore └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Git-Cheat-Sheet 2 | 3 | > Click ⭐ if you like the project. Pull Request are highly appreciated. Follow me [@sisitarak](https://www.linkedin.com/in/sisitarak/) for more updates. 4 | 5 | 6 | 7 | ### Table-of-Contents 8 |
9 | 10 | Hide/Show table of contents 11 | 12 | 13 | | No. | Topics | 14 | | --- | -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 15 | | 1 | [What is Git?](#what-is-git) | 16 | | 2 | [What is GitHub?](#What-is-github) | 17 | | | **Cheat Sheet with Commands** | 18 | | 3 | [What is Git Cheat Sheet?](#what-is-git-cheat-sheet) | 19 | | 4 | [Disclaimer](#disclaimer) | 20 | 21 | 22 | 23 | 1. ### What is Git? 24 | 25 | Git is the free and open source distributed version control system that's responsible for everything GitHub related that happens locally on your computer. This cheat sheet features the most important and commonly 26 | used Git commands for easy reference. 27 | 28 | 29 | **[⬆ Back to Top](#table-of-contents)** 30 | 31 | 32 | 33 | 3. ### What is GitHub? 34 | 35 | GitHub is a web-based platform used for version control and collaboration on projects primarily based on Git. It offers a range of features including source code management (version control), issue tracking, pull 36 | requests, code review, and project management tools. 37 | 38 | GitHub is widely used by developers and teams for 39 | 40 | - managing and sharing code, 41 | - collaborating on projects, and 42 | - contributing to open-source software. 43 | 44 | 45 | **[⬆ Back to Top](#table-of-contents)** 46 | 47 | 48 | 49 | 4. ### What is Git Cheat Sheet? 50 | 51 | **SETUP** 52 | 53 | Configuring user information used across all local repositories 54 | 55 | '''bash 56 | 57 | 58 | # set a name that is identifiable for credit when review version history 59 | git config --global user.name “[firstname lastname]” 60 | 61 | 62 | # set an email address that will be associated with each history marker 63 | git config --global user.email “[valid-email]” 64 | 65 | 66 | # set automatic command line coloring for Git for easy reviewing 67 | git config --global color.ui auto 68 | 69 | 70 | ''' 71 | 72 | 73 | **INIT** 74 | 75 | Configuring user information, initializing and cloning repositories 76 | 77 | '''bash 78 | 79 | 80 | # initialize an existing directory as a Git repository 81 | git init 82 | 83 | 84 | # retrieve an entire repository from a hosted location via URL 85 | git clone [url] 86 | 87 | 88 | ''' 89 | 90 | 91 | **STAGE & SNAPSHOT** 92 | 93 | Working with snapshots and the Git staging area 94 | 95 | '''bash 96 | 97 | 98 | # show modified files in working directory, staged for your next commit 99 | git status 100 | 101 | 102 | # add a file as it looks now to your next commit (stage) 103 | git add [file] 104 | 105 | 106 | # unstage a file while retaining the changes in working directory 107 | git reset [file] 108 | 109 | 110 | # diff of what is changed but not staged 111 | git diff 112 | 113 | 114 | # diff of what is staged but not yet committed 115 | git diff --staged 116 | 117 | 118 | # commit your staged content as a new commit snapshot 119 | git commit -m “[descriptive message]” 120 | 121 | 122 | ''' 123 | 124 | 125 | **BRANCH & MERGE** 126 | 127 | Isolating work in branches, changing context, and integrating changes 128 | 129 | '''bash 130 | 131 | 132 | # list your branches. a * will appear next to the currently active branch 133 | git branch 134 | 135 | 136 | # create a new branch at the current commit 137 | git branch [branch-name] 138 | 139 | 140 | # switch to another branch and check it out into your working directory 141 | git checkout 142 | 143 | 144 | # merge the specified branch’s history into the current one 145 | git merge [branch] 146 | 147 | 148 | # show all commits in the current branch’s history 149 | git log 150 | 151 | 152 | ''' 153 | 154 | 155 | **INSPECT & COMPARE** 156 | 157 | Examining logs, diffs and object information 158 | 159 | '''bash 160 | 161 | 162 | # show the commit history for the currently active branch 163 | git log 164 | 165 | 166 | # show the commits on branchA that are not on branchB 167 | git log branchB..branchA 168 | 169 | 170 | # show the commits that changed file, even across renames 171 | git log --follow [file] 172 | 173 | 174 | # show the diff of what is in branchA that is not in branchB 175 | git diff branchB...branchA 176 | 177 | 178 | # show any object in Git in human-readable format 179 | git show [SHA] 180 | 181 | 182 | ''' 183 | 184 | 185 | **TRACKING PATH CHANGES** 186 | 187 | Versioning file removes and path changes 188 | 189 | '''bash 190 | 191 | 192 | # delete the file from project and stage the removal for commit 193 | git rm [file] 194 | 195 | 196 | # change an existing file path and stage the move 197 | git mv [existing-path] [new-path] 198 | 199 | 200 | # show all commit logs with indication of any paths that moved 201 | git log --stat -M 202 | 203 | 204 | ''' 205 | 206 | 207 | **IGNORING PATTERNS** 208 | 209 | Preventing unintentional staging or commiting of files 210 | 211 | '''bash 212 | 213 | 214 | # system wide ignore pattern for all local repositories 215 | git config --global core.excludesfile [file] 216 | 217 | 218 | # Save a file with desired patterns as .gitignore with either direct string matches or wildcard globs. 219 | logs/ 220 | *.notes 221 | pattern*/ 222 | 223 | 224 | ''' 225 | 226 | 227 | **SHARE & UPDATE** 228 | 229 | Retrieving updates from another repository and updating local repos 230 | 231 | '''bash 232 | 233 | 234 | # add a git URL as an alias 235 | git remote add [alias] [url] 236 | 237 | 238 | # fetch down all the branches from that Git remote 239 | git fetch [alias] 240 | 241 | 242 | # merge a remote branch into your current branch to bring it up to date 243 | git merge [alias]/[branch] 244 | 245 | 246 | # Transmit local branch commits to the remote repository branch 247 | git push [alias] [branch] 248 | 249 | 250 | # fetch and merge any commits from the tracking remote branch 251 | git pull 252 | 253 | 254 | ''' 255 | 256 | 257 | **REWRITE HISTORY** 258 | 259 | Rewriting branches, updating commits and clearing history 260 | 261 | '''bash 262 | 263 | 264 | # apply any commits of current branch ahead of specified one 265 | git rebase [branch] 266 | 267 | 268 | # clear staging area, rewrite working tree from specified commit 269 | git reset --hard [commit] 270 | 271 | 272 | ''' 273 | 274 | 275 | **TEMPORARY COMMITS** 276 | 277 | Temporarily store modified, tracked files in order to change branches 278 | 279 | '''bash 280 | 281 | 282 | # Save modified and staged changes 283 | git stash 284 | 285 | 286 | # list stack-order of stashed file changes 287 | git stash list 288 | 289 | 290 | # write working from top of stash stack 291 | git stash pop 292 | 293 | 294 | # discard the changes from top of stash stack 295 | git stash drop 296 | 297 | 298 | ''' 299 | 300 | 301 | **[⬆ Back to Top](#table-of-contents)** 302 | 303 | 304 | 305 | 5. ### Disclaimer 306 | 307 | **Note:** 308 | 309 | This Git cheat sheet is provided for basic informational purposes only. While we strive to ensure the accuracy and reliability of the information presented here, it is important to note that Git commands and workflows may vary based on factors such as operating system, Git version, and individual project requirements. 310 | 311 | Before executing any Git commands, we strongly recommend reviewing the official Git documentation and exercising caution, especially when working with sensitive or production-level repositories. Additionally, always make sure to back up your data and verify the impact of any commands on your repository before proceeding. 312 | 313 | By using this Git cheat sheet, you acknowledge and agree that the authors and contributors are not liable for any damages or losses resulting from the use or misuse of the information provided herein. 314 | 315 | Good luck and Pull Request are highly appreciated 😊 316 | --------------------------------------------------------------------------------