├── .github └── FUNDING.yml ├── CONTRIBUTING.md ├── Contributor Covenant Code of Conduct.md ├── LICENSE.md └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: YatharthChauhan2362 # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Git-CheatSheet 2 | 3 | ## Your all in one Git, Github and Terminal Cheatsheet.. Feel free to contribute and commit and raise PR 4 | 5 | --- 6 | 7 | ## Contributions Needed: 8 | 9 | - ### Contributing to current Open Issues. 10 | - ### Adding Important yet Missed out Commands. 11 | - ### Other Contributions, Issues, Enhancements are welcomed as well. 12 | 13 | --- 14 | 15 | ## How to contribute? 16 | 17 | ### `STEP 1` : Fork [this](https://github.com/YatharthChauhan2362/Git-Github-Learning.git) repository. 18 | 19 | ### `STEP 2` : Clone your forked copy of the project. 20 | 21 | ``` 22 | git clone https://github.com//Git-CheatSheet.git 23 | ``` 24 | 25 | ### `STEP 3` : Navigate to the project directory . 26 | 27 | ``` 28 | cd Git-CheatSheet 29 | ``` 30 | 31 | ### `STEP 4` : Add a reference (remote) to the original repository. 32 | 33 | ``` 34 | git remote add upstream https://github.com/YatharthChauhan2362/Git-Github-Learning.git 35 | ``` 36 | 37 | ### `STEP 5` : Check the remotes for this repository. 38 | 39 | ``` 40 | git remote -v 41 | ``` 42 | 43 | ### `STEP 6` : Always take a pull from the upstream repository to your master branch to keep it at par with the main project (updated repository). 44 | 45 | ``` 46 | git pull upstream master 47 | ``` 48 | 49 | ### `STEP 7` : Create a new branch. 50 | 51 | ``` 52 | git checkout -b 53 | ``` 54 | 55 | ### `STEP 8` : Perform your desired changes to the code base. 56 | 57 | ### `STEP 9` : Track your changes . 58 | 59 | ``` 60 | git add . 61 | ``` 62 | 63 | ### `STEP 10` : Commit your changes . 64 | 65 | ``` 66 | git commit -m "Relevant message" 67 | ``` 68 | 69 | ### `STEP 11` : Push the committed changes in your feature branch to your remote repo. 70 | 71 | ``` 72 | git push -u origin 73 | ``` 74 | 75 | ### `STEP 12` : To create a pull request, click on `compare and pull requests`. Please ensure you compare your feature branch to the desired branch of the repository you are supposed to make a PR to. 76 | 77 | ### `STEP 13` : Add appropriate title and description to your pull request explaining your changes and efforts done. 78 | 79 | ### `STEP 14` : Click on `Create Pull Request`. 80 | 81 | ### Voila! You have made a PR to the Git-CheatSheet. Sit back patiently and relax while your PR is reviewed 82 | 83 | --- 84 | 85 | ## Points to remember: 86 | 87 | - ### Anyone who is sending a Pull Request make sure that you Refactor your code. 88 | - ### Properly Organize the things that you add or delete and mention them in you commits description 89 | - ### We will carry out this task after every Major Update has been done 90 | - ### But just stating this here so that people from now on make sure to properly organize those big chunks of codes. 91 | 92 | --- 93 | 94 | ## Thank You. 95 | -------------------------------------------------------------------------------- /Contributor Covenant Code of Conduct.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | - Demonstrating empathy and kindness toward other people 21 | - Being respectful of differing opinions, viewpoints, and experiences 22 | - Giving and gracefully accepting constructive feedback 23 | - Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | - Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | - The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | - Trolling, insulting or derogatory comments, and personal or political attacks 33 | - Public or private harassment 34 | - Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | - Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | yatharthchauhan2024@gmail.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Yatharth Chuahan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Git-Github Commands 2 | 3 | ## Your all in one Git, Github and Terminal Commands! 4 | 5 | --- 6 | 7 | - ### [LinkedIn Certification Credentials](https://www.linkedin.com/learning/certificates/4aa67798501364d4bdc00d1cd1934e954e7f3d878f0fafc49ced607c42a3eda0) 8 | --- 9 | 10 | 11 | # **WELCOME TO THE GIT COMMANDS** 12 | 13 | AUTHOR: Yatharth Chauhan (Github: YatharthChauhan2362) 14 | REFERENCE: Learning Git and Github (LinkedIn Learning) 15 | DESCRIPTION: Your very own Git AND Github Cheat Sheet having basic Windows Terminal Cheats as well! 16 | 17 | **_GO ON FROM HERE, ALL THE BEST_** 18 | 19 |
20 | 21 | ## TERMINAL BASICS: 22 | 23 | It is the LIST command which LISTS all the contents of a Directory 24 | 25 | $ ls 26 | 27 | LOCATES to a directory and then LISTS the contents 28 | 29 | $ ls foldername 30 | 31 | PRINT WORKING DIRECTORY 32 | 33 | $ pwd 34 | 35 | CHANGES and HOPS onto the respective Working Directory 36 | 37 | $ cd C:\User\Yatharth\foldername 38 | 39 | HOPS onto the Parent Directory of the Working Directory 40 | 41 | $ cd .. 42 | 43 | CLEARS the used Terminal 44 | 45 | $ clear 46 | 47 | QUITS out of a entered command 48 | 49 | $ q 50 | 51 | CREATES an Empty directory inside the Working Directory 52 | 53 | $ mkdir foldername 54 | 55 | DELETES the file 56 | 57 | $ rm filename 58 | 59 | DELETES the directory 60 | 61 | $ rm -rf foldername 62 | 63 | OPENS the File Explorer to the ROOT Directory 64 | 65 | $ start . 66 | 67 |
68 | 69 | ## SETTING GIT USER NAME AND EMAIL: 70 | 71 | to CHECK if git User-Name is set 72 | 73 | $ git config user.name 74 | 75 | to CHECK if git User-Email is set 76 | 77 | $ git config user.email 78 | 79 | To SET or CHANGE git User-Name 80 | 81 | $ git config --global user.name "Yatharth Chauhan" 82 | 83 | To SET or CHANGE git User-Email 84 | 85 | $ git config --global user.email yatharthchauhan2024@gmail.com 86 | 87 | to SET or CHANGE default code editor as VsCode 88 | 89 | $ git config --global core.editor "code --wait" 90 | 91 | to CHANGE git User-Name and git User-Email directly in the config file using vim 92 | 93 | $ git config --global --edit 94 | 95 | to STORE git User-Name and git User-Email in disk 96 | 97 | $ git config credential.helper store 98 | 99 | To EXIT vim 100 | 101 | $ escape + :wq 102 | 103 |
104 | 105 | ## GETTING GIT HELP: 106 | 107 | Use for more details and examples on any of the below (or above) commands e.g. push, pull etc. 108 | 109 | $ git command --help 110 | 111 |
112 | 113 | ## CREATING A GIT REPOSITORY: 114 | 115 | `STEP 1` : INITIALIZES an empty repository 116 | 117 | $ git init 118 | 119 | `STEP 2` : to CHECK the status of a repository, a .git directory is created, all git history is deleted if .git is deleted 120 | 121 | $ git status 122 | 123 |
124 | 125 | ## STAGING FILE/FILES OF THE REPOSITORY: 126 | 127 | _(to keep a track of modifications or changes)_ 128 | 129 |
130 | 131 | STAGES the file 132 | 133 | $ git add filename.txt 134 | 135 | UN-STAGES the file 136 | 137 | $ git rm --cached filename.txt 138 | 139 | STAGES all files in the repository 140 | 141 | $ git add --all 142 | 143 | OR 144 | 145 | $ git all . 146 | 147 | OR 148 | 149 | $ git add . 150 | 151 |
152 | 153 | ## UNDOING CHANGES IN THE REPOSITORY: 154 | 155 | _(If a developer wants to remove untracked files from a git working tree, the easiest way to do it is with the ‘git clean’ command)_ 156 | 157 |
158 | 159 | DRY run 160 | 161 | $ git clean -n 162 | 163 | Force untracked file deletion 164 | 165 | $ git clean -f 166 | 167 | Force untracked directory deletion 168 | 169 | $ git clean -f -d 170 | 171 |
172 | 173 | ## COMMITING A COMMIT: 174 | 175 |
176 | 177 | COMMITS the STAGED files with a commit message 178 | 179 | $ git commit -m "commit message" 180 | 181 | SKIPS the Staging part and directly COMMITS 182 | 183 | $ git commit -a -m "commit message" 184 | 185 | LOGS all the commits done to the repository 186 | 187 | $ git log 188 | 189 | LOG commits in a single line 190 | 191 | $ git log --oneline 192 | 193 | AMMENDS the previous commit 194 | 195 | $ git commit --ammend 196 | 197 | LOGS the changes 198 | 199 | $ git diff 200 | 201 |
202 | 203 | ## EVERYTHING ABOUT GIT IGNORE: 204 | 205 | _(git doesnt consider the files/folders which are in .gitignore)_ 206 | 207 | > You may want to ignore certain files for multiple reasons: 208 | 209 | 1. The files contain sensitive data. 210 | 2. The files are system specific and do not need to exist on every machine’s copy. 211 | 3. Excluding the files maintains system security rules and privileges. (Remember, Git repos only contain the files necessary to get tech support—not to share the entire software.) 212 | 213 | `STEP 1` : create a .gitignore file 214 | 215 | `STEP 2` : add files or folders inside the file to ignore, now the files are are untracked by github and wont be staged or commited 216 | 217 |
218 | 219 | ## GITIGNORE PATTERNS 220 | 221 | _Preventing unintentional staging or commiting of files_ 222 | 223 | `logs/ // ignoring all files inside logs folder *.notes // ignoring all files with .notes file extension pattern*/ // ignoring all pattern* files or folders` 224 | 225 | Save a file with desired patterns as `.gitignore` with either direct string 226 | matches or wildcard globs. 227 | 228 |
229 | 230 | ## GIT BRANCHING: 231 | 232 | _(if you are trying something out but do on want to play with the main branch)_ 233 | 234 | LOGS all the branches of the Working Repository with an \* in the Current Head or GO to .git\refs\heads 235 | 236 | $ git branch 237 | 238 | CREATES a new branch but the branch is not yet SWITCHED 239 | 240 | $ git branch branchname 241 | 242 | SWITCHES the Branch from one to another or CHANGING HEAD, but the current changes need to be STASHED or COMMITED 243 | 244 | $ git switch branchname 245 | 246 | CREATES a new branch and then SWITCHES to the branches 247 | 248 | $ git switch -c newbranch 249 | 250 | CREATES a new branch and then SWITCHES to the branch 251 | 252 | $ git checkout -b newbranch 253 | 254 | DELETES newbranch, but you cant be Headed on the Branch you want to delete 255 | 256 | $ git branch -D newbranch 257 | 258 | CHANGES the name of the Branch you are Headed on 259 | 260 | $ git branch -M finalbranch 261 | 262 | TO DELETE A REMOTE BRANCH IN GIT 263 | 264 | $ git push --delete origin branchname 265 | 266 | TO LIST all remote branches 267 | 268 | $ git branch -a 269 | 270 |
271 | 272 | ## MERGING BRANCHES: 273 | 274 | _FAST FORWARD MERGE (NO CHANGES done on the Master Branch)_ 275 | 276 | `STEP 1` : SWITCH the HEAD first to the first branch 277 | 278 | $ git switch master 279 | 280 | `STEP 2` : MERGES newbranch into master with HEAD on master 281 | 282 | $ git merge newbranch 283 | 284 | _NOT ALL MERGES ARE FAST FORWARD MERGES_ 285 | 286 | 1. WITHOUT MERGE CONFLICTS 287 | 288 | $ git switch master 289 | 290 | CREATES a new commit unlike fastforwarding merges 291 | 292 | $ git merge -m "mergering message" 293 | 294 | 2. MERGE CONFLICTS 295 | 296 | _(only if conflict message occurs)_ 297 | 298 | `STEP 1` : OPEN UP files having merge conflicts 299 | 300 | `STEP 2` : REMOVE the conflicts 301 | 302 | OPTION 1: ACCEPT INCOMING CHANGES 303 | 304 | OPTION 2: ACCEPT CURRENT CHANGES 305 | 306 | OPTION 3: ACCEPT BOTH CHANGES 307 | 308 | OPTION 4: COMPARE CHANGES 309 | 310 | `STEP 3` : REMOVE the conflict markers 311 | 312 | `STEP 4` : STAGE and COMMIT the changes 313 | 314 | 3. ABORT MERGE (UNDO merge when mistakenly code merged & multiple unresolvable merging conflicts occur) 315 | 316 | $ git merge --abort 317 | 318 |
319 | 320 | ## STASHING IN GIT: 321 | 322 | _(needed when switching branches but the changes arent commit ready but by not stashing, the changes will behave wierdly)_ 323 | 324 | 1. CHANGES WILL EITHER COME IN THE DESTINATION BRANCH 325 | 326 | 2. GIT WONT ALLOW SWITCHING IF THERE ARE CONFLICTS 327 | 328 | _(hence to prevent this staging is important, its like a save but doesnt show up anywhere unless popped)_ 329 | 330 | STASHES the changes 331 | 332 | $ git stash 333 | 334 | UN STASHES the changes, use it when you resume your work 335 | 336 | $ git stash pop 337 | 338 | APPLY stashed changes into another or the same branch 339 | 340 | $ git stash apply 341 | 342 | 3. IF WORKING WITH MULTIPLE STASHES 343 | 344 | LOGS all the stashes 345 | 346 | $ git stash list 347 | 348 | STASHES the changes in the Stash index 1 349 | 350 | $ git stash apply stash@{1} 351 | 352 | DELETES the stash, p.s. applying the stash doesnt delete it 353 | 354 | $ git stash drop stash@{1} 355 | 356 | CLEARS the whole stash list 357 | 358 | $ git stash clear 359 | 360 |
361 | 362 | ## TIME TRAVELLING WITH GIT: 363 | 364 | 1. TO JUST CHECK WHAT THE REPOSITORY LOOKED LIKE IN THE COMMIT ID 604a39a 365 | 366 | DETACHES HEAD and attaches it to the commit with the commit id 604a39a 367 | 368 | _(this is not normal because HEAD is meant to map a whole branch and not a specific commit)_ 369 | 370 | $ git checkout 604a39a 371 | 372 | DETACHES HEAD and ATTACHES it to the previous commit 373 | 374 | $ git checkout HEAD~1 375 | 376 | RE-ATTACHES HEAD and now the head properly maps onto the master branch 377 | 378 | $ git switch master 379 | 380 | 2. TO CREATE AND WORK WITH A NEW BRANCH AT COMMIT ID 604a39a 381 | 382 | $ git checkout 604a39a 383 | 384 | now the HEAD is perfect where it should have been 385 | 386 | $ git switch -c "new branch" 387 | 388 | 3. TO RESTORE ALL CHANGES TO TRACKED FILES 389 | $ git reset origin/main --hard 390 | 4. TO RESTORE CHANGES OF A PARTICULAR FILE TO THE LAST COMMIT 391 | 392 | $ git checkout HEAD filename.txt 393 | 394 | OR 395 | 396 | $ git restore filename.txt 397 | 398 | 5. TO RESTORE CHANGES OF A PARTICULAR FILE TO THE SECOND-LAST COMMIT 399 | 400 | $ git restore --source HEAD~1 filename.txt 401 | 402 | 6. UNSTAGE A FILE 403 | 404 | $ git restore --unstaged filename.txt 405 | 406 | 7. RESETING THE REPOSITORY TO A PARTICULAR COMMIT 407 | 408 | RESETS the HEAD to the commit id 604a39a, but it doesnt delete the changes. 409 | 410 | _(it like there is no commit made after commit id 604a39a)_ 411 | 412 | $ git reset 604a39a 413 | 414 | LOOSES the commit as well as LOOSES the contents of the commit 415 | 416 | $ git reset --hard 604a39a 417 | 418 | 8. REVERTING THE REPOSITORY TO A PARTICULAR COMMIT 419 | 420 | REVERTS the changes in that particular commit and CREATES a new commit after reverting changes 421 | 422 | _(p.s. this helps while collaboration)_ 423 | 424 | $ git revert 604a39a 425 | 426 |
427 | 428 | ## CREATING GITHUB RESPOSITORIES: 429 | 430 | 1. BUILD A NEW REPOSITORY AND START WORKING FROM SCRATCH (BY REMOTING) 431 | 432 | `STEP 1` : CREATE A NEW REPOSITORY ON YOUR GITHUB WEBSITE AND COPY THE URL 433 | 434 | `STEP 2` : CREATES an empty git repository 435 | 436 | $ git init 437 | 438 | `STEP 3` : WRITE YOUR PIECE OF CODE 439 | 440 | `STEP 4` : a commit is needed to push any files to github 441 | 442 | $ git commit -a -m "first commit" 443 | 444 | `STEP 5` : CREATES a new REMOTE DESTINATION for the github repository 445 | 446 | $ git remote add origin 447 | 448 | `STEP 6` : LOGS out the REMOTE URL if any 449 | 450 | $ git remote -v 451 | 452 | `STEP 7` : PUSHES the last commited code to github 453 | 454 | $ git push -u origin branchname 455 | 456 | _(p.s. the -u is like a setting the origin remote and master branch as a default so that we can use just this in futur)_ 457 | 458 | $ git push 459 | 460 | 2. BUILD A NEW REPOSITORY AND START WORKING FROM SCRATCH (BY CLONING) 461 | 462 | `STEP 1` : CREATE A NEW REPOSITORY ON YOUR GITHUB WEBSITE AND COPY THE URL 463 | 464 | `STEP 2` : CLONES as well as automatically sets the REMOTE DESTINATION 465 | 466 | $ git clone 467 | 468 | `STEP 3` : WRITE YOUR PIECE OF CODE 469 | 470 | `STEP 4` : a commit is needed to push any files to github 471 | 472 | $ git commit -a -m "first commit" 473 | 474 | `STEP 5` : PUSHES the last commited code to github 475 | 476 | $ git push -u origin branchname 477 | 478 | _(p.s. the -u is like a setting the origin remote and master branch as a default so that we can use just this in future)_ 479 | 480 | $ git push 481 | 482 | 3. CONNECT YOUR PREEXISTING GIT REPOSITORY TO A NEW GITHUB REPOSITORY 483 | 484 | `STEP 1` : CREATE A NEW REPOSITORY ON YOUR GITHUB WEBSITE AND COPY THE URL 485 | 486 | `STEP 2` : CREATES a new REMOTE DESTINATION for the github repository 487 | 488 | $ git remote add origin 489 | 490 | `STEP 3` : LOGS out the REMOTE URL if any 491 | 492 | $ git remote -v 493 | 494 | `STEP 4` : PUSHES the last commited code to github 495 | 496 | $ git push -u origin branchname 497 | 498 | _(p.s. the -u is like a setting the origin remote and master branch as a default so that we can use just this in future)_ 499 | 500 | $ git push 501 | 502 |
503 | 504 | ## THE origin/master THEORY: 505 | 506 | \*origin/master is called as a REMOTE TRACKING BRANCH, It is a Remote Branch that represents our local Branch 507 | 508 | LOGS the remote tracking branch 509 | 510 | $ git branch -r 511 | 512 | to check out the remote branch code: DETACHES HEAD onto the remote tracking HEAD, in a case where the local branch is ahead of the remote branch and not up to date, push to make it up to date 513 | 514 | $ git checkout origin/master 515 | 516 | now if you CLONE a repository with multiple branches and run 517 | 518 | $ git branch 519 | 520 | then technically all the branches should have been logged, but this is not the case only master branch is logged, this is because by default only local master branch is connected to the remote branch but others need to be connected in order to work with them and the simplest way to do so is: 521 | 522 | to check all the branches available 523 | 524 | $ git branch -r 525 | 526 | this automatically CONNECTS the two branches and we can freely work on them now 527 | 528 | $ git switch branchname 529 | 530 | now this correctly LOGS all the connected branches 531 | 532 | $ git branch 533 | 534 |
535 | 536 | ## FETCHING: 537 | 538 | _FETCHING allows to get changes from the github remote repository to our local git repository but DOESN'T CHANGE into the working directory_ 539 | 540 | To RECIEVE the new commits 541 | 542 | $ git fetch 543 | 544 | CREATES a new branch having the changes but this doesnt interfere in the working directory, the origin/master now heads on to this new branch and the master branch would be one branch behind the origin/master) 545 | 546 | $ git fetch origin 547 | 548 | or 549 | 550 | $ git fetch origin branchname 551 | 552 | to CHECK out the remote branch code: DETACHES HEAD onto the remote tracking HEAD, in a case where the local branch is ahead of the remote branch and not up to date, push to make it up to date) 553 | 554 | $ git checkout origin/master 555 | 556 |
557 | 558 | ## PULLING = FETCHING + MERGING: 559 | 560 | PULLS the changes and merges the changes with the branch you want to OR default 561 | 562 | $ git pull origin 563 | 564 | or 565 | 566 | $ git pull origin branchname 567 | 568 | _SOLVE MERGE CONFLICTS IF ANY_ 569 | 570 |
571 | 572 | ## FORCE PUSH AND PULL: 573 | 574 | $ git push origin -f 575 | 576 | This will delete your previous commit(s) and push your current one. f signifies force . 577 | 578 | $ git pull --rebase=interactive 579 | 580 | OR 581 | 582 | $ git pull --rebase=i 583 | 584 | _This is nothing but fetch + rebase. This will invoke rebase in interactive mode where you can choose how to apply each individual commit that isn't in the history you are rebasing on._ 585 | 586 | _REFER TIME TRAVELLING WITH GIT for more git force pulling commands_ 587 | 588 |
589 | 590 | ## GITHUB COLLABORATION: 591 | 592 | `CENTRALIZED WORKFLOW` : 593 | 594 | Everybody works on the same main branch and push and pull in the main branch only. 595 | 596 | `FEATURE BRANCH WORKFLOW` : 597 | 598 | Every feature is pushed upon another independent branch to minimize mess. 599 | 600 | `GITHUB PULL REQUEST WORKFLOW` : 601 | 602 | Once a pull request is opened, you can discuss and review the potential changes with collaborators and add follow-up commits before your changes are merged into the base branch. 603 | 604 | `GITHUB FORKS AND CLONE WORKFLOW` : 605 | 606 | Forking nd then opening a pull request to the owner of the main repository. 607 | 608 |
609 | 610 | ## GIT REBASING: 611 | 612 | REBASES or SEPARATES the history of the newbranch from the master branch 613 | 614 | $ git switch newbranch 615 | 616 | REBASES or MERGES master into newbranch 617 | 618 | $ git rebase master 619 | 620 | CONFLICTS WHILE REBASING 621 | 622 | `STEP 1` : Resolve the CONFLICTS MANUALLY 623 | 624 | `STEP 2` : 625 | 626 | $ git add . 627 | 628 | `STEP 3` : 629 | 630 | $ git rebase --continue 631 | 632 |
633 | 634 | ## INTERACTIVE REBASING: 635 | 636 | OPENS up the code editor where you can play with the nth last commits and above 637 | 638 | $ git rebase -i HEAD~n 639 | 640 | CHANGES the name of a specific commit 641 | 642 | reword 643 | 644 | COMBINES the changes of that commit to the previous commit and then deletes it 645 | 646 | fixup 647 | 648 | DELETES the commit and the commit changes as if they were never written 649 | 650 | drop 651 | 652 |
653 | 654 | ## GIT TAGS: 655 | 656 | TAGS and DENOTES the importance of a commit 657 | 658 | _Semanting Versioning Format is widely used for tags and releases (v1.0.1)_ 659 | 660 | LOGS all the tags 661 | 662 | $ git tag -l 663 | 664 | LOGS tag name v17 665 | 666 | $ git tag -l "v17" 667 | 668 | LOGS tag names that start with v17.. 669 | 670 | $ git tag -l "v17*" 671 | 672 | LOGS tags which include beta in their name 673 | 674 | $ git tag -l "*beta*" 675 | 676 | to CHECKOUT the code in the tag, use CHECKOUT 677 | 678 | LOGS the changes between both the versions 679 | 680 | $ git diff v16.0.1 v16.1.1 681 | 682 | CREATES a lightweight tag 683 | 684 | $ git tag tagname 685 | 686 | CREATES an annotated tag 687 | 688 | $ git tag -a tagname 689 | 690 | LOGS the message of the git tag "annotated" 691 | 692 | $ git show annotation 693 | 694 | CREATES a tag at commit number 604a39a 695 | 696 | $ git tag -a tagname 604a39a 697 | 698 | DELETES the tag 699 | 700 | $ git tag -d tagname 701 | 702 | TRANSFERS tags to remote servers 703 | 704 | $ git push origin tagname 705 | 706 |
707 | 708 | ## GITHUB DESKTOP: 709 | 710 | Interact with GitHub using a GUI instead of the command line or a web browser 711 | 712 | 1.Installing and authenticating 713 | 714 | `STEP 1` : Download GitHub Desktop for Windows using this [URL](https://desktop.github.com/). 715 | 716 | `STEP 2` : Click on “File” on the navbar, go down to “Options,” choose “Accounts,” and get authentication. 717 | 718 | 2.Contributing to projects with GitHub Desktop 719 | 720 | `STEP 1` : You can create a new repository by selecting the File menu and clicking New repository. 721 | 722 | `STEP 2`: You can add a repository from your local computer by selecting the File menu and clicking Add Local Repository. 723 | 724 | `STEP 3` : You can clone a repository from GitHub by selecting the File menu and clicking Clone Repository. 725 | 726 | `STEP 4` : You can use GitHub Desktop to create a branch of a project. 727 | 728 | `STEP 5` : After you make changes to a branch, you can review them in GitHub Desktop and make a commit to keep track of your changes. 729 | 730 | `STEP 6` : You can use GitHub Desktop to create issues or pull requests to collaborate on projects with other people. 731 | 732 | `STEP 7` : When you make changes to your local repositories or when other people make changes to the remote repositories, you will need to sync your local copy of the project with the remote repository. 733 | 734 |
735 | 736 | ## Extensions for Github 737 | 738 | if you're a Developer and you use Github as your Version Control Tools, there's likely some functionality you wish it had. To help with these there are some best extension that you can use for Github. 739 | 740 |
741 | 742 | 1. `Octotree`: 743 | This is a feature-rich extensions that enhance your Github experience. It facilitates you with code tree to all the github repositories, which simplifies your file search and navigation. (though now this is by default provided by Github) 744 | It also offers you bookmarking repositories, files and PRs. It increase your productivity at work by lazy-loading and caching. Besides these, it offers several other features in it's Paid Version. 745 | 746 | _Download:_ Octotree for [Google Chrome](https://chrome.google.com/webstore/detail/octotree-github-code-tree/bkhaagjahfmjljalopjnoealnfndnagc)| [Edge](https://microsoftedge.microsoft.com/addons/detail/octotree-github-code-tr/joagmknfcgpikbadjkaikmnhpjadihjg)| [Firefox](https://addons.mozilla.org/en-US/firefox/addon/octotree/) | [Safari](https://apps.apple.com/us/app/octotree-pro/id1457450145?mt=12) (Free, Paid) 747 | 748 |
749 | 750 | 2. `GitZip for GitHub`: 751 | Every day and night we are facing situation to download the files from Github. GitZip for GitHub provides you the simpleast way for downloading files or subfolders individually from any repository. You can select items by double-clicking the empty space after the file name and clicking the download arrow that appears in the bottom-right corner. 752 | 753 | Alternatively, right-click anywhere, hover the cursor over GitZip Download and decide whether to download the entire folder or selected files. 754 | 755 | It also offers the dark theme and is completely free to use. 756 | 757 | _Download:_ Gitzip for Github for [Google Chrome](https://chrome.google.com/webstore/detail/gitzip-for-github/ffabmkklhbepgcgfonabamgnfafbdlkn) 758 | 759 |
760 | 761 | 3. `Refined Github`: 762 | Refined GitHub is another Chrome extension that adds more than 200 features to your GitHub. Most of these features are focused on improving the interface and experience. 763 | 764 | It highlights the most useful comments and shows reaction avatars for comments. It adds gray dots and arrows to the whitespace in code, making them visible. Similarly, it makes the pull request references and URLs in code clickable. 765 | 766 | With hundreds of features available. The best part is that You can turn off any of these features individually by going to _Extensions_ > _Refined GitHub_ > _Extension Options_. 767 | This free extension has over 50,000 downloads on Chrome. It’s available on Firefox and Safari too. 768 | 769 | _Download:_ Refined GitHub for [Google Chrome](https://chrome.google.com/webstore/detail/refined-github/hlepfoohegkhhmjieoechaddaejaokhf) | [Safari](https://apps.apple.com/us/app/refined-github/id1519867270) | [Firefox](https://addons.mozilla.org/en-US/firefox/addon/refined-github-/) (Free) 770 | 771 |
772 | 773 | **_YOU DID IT, SIT BACK AND BE PROUD OF YOURSELF_** 774 | 775 | ### Thank You : 776 | --------------------------------------------------------------------------------