├── Hacktoberfest Slides.pptx └── README.md /Hacktoberfest Slides.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abdullah-ch/Git-Cheat-Sheet/192079ee157e2acbbceee133cb314646c7fe769a/Hacktoberfest Slides.pptx -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Git-Cheat-Sheet 2 | ## Git Bash Terminal 3 | [Download the Terminal from here](https://git-scm.com/downloads) 4 | 5 | ### 0-> Configuring the Bash Terminal 6 | `git config --global user.name “Your Name”` 7 | `git config --global user.email “Youremail@anything.com”` 8 | ### 1-> Creating a Repository 9 | `git init ` 10 | `git remote add origin [repoLink] ` 11 | #### Origin works like a pointer to the repoLink, making the referencing easier 12 | `git remote -v ` 13 | `git add . ` 14 | `git commit -m "[your message]" ` 15 | `git push origin [branchName] ` 16 | ### 2-> Creating a Pull Request 17 | #### Fork the desired Repo 18 | `git clone [forkedRepoLink]` 19 | #### Do your Contribution 20 | `git add .` 21 | `git commit -m "your message"` 22 | `git push origin [branchName]` 23 | ### 3-> Getting Updates from the Main Repo to Your Forked Repo 24 | `git remote add upstream [originalRepoLink]` 25 | #### Upstream Acts as a pointer towards the Main Repo's remote 26 | `git pull upstream master` 27 | #### Changes from the Main remote are pulled Locally 28 | `git push origin` 29 | #### Changes are pushed to the Forked Remote Repo ! 30 | ### 4-> Get Information about Your Commits 31 | `git log --pretty=oneline` 32 | ### 5-> Move to Your Desired Commit or Branch 33 | `git checkout hash/branch` 34 | ### 6-> Undoing Staged Files 35 | `git reset HEAD ` 36 | #### where HEAD can be your Hash number (First Four Digits will do fine) or your Branch Name 37 | ### 7-> Undoing Commited Files 38 | `git revert HEAD` 39 | #### where HEAD can be your Hash number (First Four Digits will do fine) or your Branch Name 40 | ### 8-> Pulling changes Locally from a Remote Repo 41 | `git pull origin [branchName]` 42 | #### Where the origin can be replaced by the respective remote pointer. 43 | ### 9-> View the state of your Staging Area and Changes in your Directory 44 | `git status` 45 | ### 10-> View the History of your Commits along with their Hash Codes of the Repo 46 | `git log --pretty=oneline` 47 | 48 | ### 11-> View the difference between branches 49 | `git diff --color thatBranchNameYouWantToCompare` 50 | 51 | ### 12-> Delete a branch remotely 52 | `git push origin --delete ` 53 | 54 | ### 13-> Unstage your changes 55 | `git reset` 56 | 57 | ### 13-> Unstage your changes and reset the working directory 58 | `git reset --hard` 59 | 60 | ### 13-> Revert back to the last commit (Undo Last Commit) 61 | `git reset HEAD~1` 62 | 63 | **OR** 64 | 65 | `git revert [last-commit-hash]` (This will create a new commit for reverted changes) 66 | 67 | 68 | ## Some Questions and Answers !! 69 | ### Q1-> I have pushed some commit/s that I shouldn't. Now, I want to remove them locally and remotely. I want my History on Github to be cleared of those wrong commits. What should I do ?? 70 | #### First, see your commits, understand them and select how many commit/s you want to delete. 71 | `git log --pretty=oneline` 72 | #### Now, choose a number of commits you want to change i.e lets say recent 4 commits and delete them locally. Type the following command and simply remove the commits in your text editor(simply delete the line) and save the file 73 | `git rebase -i HEAD~4` 74 | #### Check your commit tree by using git log command and become sure that your commits have been removed locally. Once, you're certain, push the remaining commits. 75 | `git push origin branchName --force` 76 | #### Your History will be altered and the commits will be removed remotely as well as locally 77 | ### Q2-> How can I pull a certain branch from GitHub ? 78 | `git fetch origin` 79 | `git branch -f [branchName]/[branchName]` 80 | `git checkout branchName` 81 | #### This command will create a branch of the same name of the remote branch that you're going to pull from 82 | 83 | 84 | 85 | 86 | 87 | --------------------------------------------------------------------------------