From cf7dc4ac462702cc148afbdd88b607fbd291c5ee Mon Sep 17 00:00:00 2001 From: Ahmed Shaikh Date: Mon, 2 Oct 2023 21:08:28 +0530 Subject: [PATCH 1/4] Update README.md Signed-off-by: Ahmed Shaikh --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index cd42cc4..8052e50 100644 --- a/README.md +++ b/README.md @@ -343,6 +343,8 @@ This project is licensed under the MIT License - see the [LICENSE](/LICENSE) fil
Gurnav Chaudhary

πŸ’»
Swati Aggrawal

πŸ’» +
Ahmed Shaikh

πŸ’» +
From 0ca0cf72f0963b294da07bad6491941a3c98ca97 Mon Sep 17 00:00:00 2001 From: Ahmed Shaikh Date: Sat, 14 Oct 2023 20:17:34 +0530 Subject: [PATCH 2/4] Update README.md Readme changes are done. Signed-off-by: Ahmed Shaikh --- README.md | 327 ++++++++++++++++++++++++------------------------------ 1 file changed, 144 insertions(+), 183 deletions(-) diff --git a/README.md b/README.md index 8052e50..85764e8 100644 --- a/README.md +++ b/README.md @@ -1,312 +1,273 @@ # Git Cheat Sheet - A quick reference guide to the most commonly used Git commands -Here is a list of the most common git commands. I've included the most common options for each command, but you can always run `git help ` to get more information. +Here is a list of the most common git commands. I've included the most common options for each command, but you can always run `git help ` to get more information. This repository also lists some great resources and books for learning git. ### πŸ–₯️ Setting up your Git information -From scratch -- Set your name associated with your user account -`git config --global user.name "NAME"` +From scratch -- Set the name associated with your user account. +```git config --global user.name "NAME"```
-Set your email associated with your user account -`git config --global user.email "youremail@abc.com"` +Set the email associated with your user account. +```git config --global user.email "youremail@abc.com"```
-Set your default editor -`git config --global core.editor "vim"` +Set your default editor: +```git config --global core.editor "vim"```
-Set your default merge tool -`git config --global merge.tool "vimdiff"` +Set your default merge tool: +```git config --global merge.tool "vimdiff"```
-Set your default push behavior -`git config --global push.default "simple"` +Set your default push behaviour: +```git config --global push.default "simple"```
-Set your default pull behavior -`git config --global pull.rebase "true"` +Set your default pull behaviour: +```git config --global pull.rebase "true"```
-Set your default branch name -`git config --global init.defaultBranch "main"` +Set your default branch name: +```git config --global init.defaultBranch "main"```
-Set your default credential helper -`git config --global credential.helper "cache --timeout=3600"` +Set your default credential helper: +```git config --global credential.helper "cache --timeout=3600"```
### πŸ›  Create a Repository -Create a new local repository -`git init [project name]` +Create a new local repository: +```git init [project name]```
-Download from an existing repository -`git clone my_url` - +Download from an existing repository: +```git clone my_url``` ### πŸ”Ž Observe your Repository - -List new or modified files not yet committed -`git status` +To list new or modified files not yet committed: +```git status```
-Show the changes to files not yet staged -`git diff` +To show the changes to files not yet staged: +```git diff```
-Show the changes to staged files -`git diff --cached` +To show the changes to staged files: +```git diff --cached```
-Show all staged and unstaged file changes -`git diff HEAD` +To show all staged and unstaged file changes: +```git diff HEAD```
-Show the changes between two commit ids -`git diff commit1 commit2` +To show the changes between two commit ids: +```git diff commit1 commit2```
-List the change dates and authors for a file -`git blame [file]` +To list the change dates and authors for a file: +```git blame [file]```
-Show the file changes for a commit id and/or file -`git show [commit]: [file]` +To show the file changes for a commit id and/or file: +```git show [commit]: [file]```
-Show full change history -`git log` +To show full change history: +```git log```
-Show the change history for file/directory including diffs -`git log -p [file/directory]` +To show the change history for file/directory including diffs: +```git log -p [file/directory]```
-Show the change history for a specific author -`git log --author="[author name]"` +To show the change history for a specific author: +```git log --author="[author name]"```
### 🌴 Working with Branches - -List all local branches -`git branch` +To list all local branches: +```git branch```
-List remote and local branches -`git branch -a` +To list remote and local branches: +```git branch -a```
-Switch to an existing branch, branch_name, and update the working directory -`git checkout branch_name` +To switch to an existing branch, branch_name, and update the working directory: +```git checkout branch_name```
-Switch to the last used branch -`git checkout - ` +To switch to the last used branch: +```git checkout - ```
-Create a new branch called the new branch -`git branch branch_name ` +To create a new branch called the new branch: +```git branch branch_name ```
-Create a local branch and switch to it -`git checkout -b branch_name` +To create a local branch and switch to it: +```git checkout -b branch_name```
-Delete the branch called my_branch -`git branch -d my_branch` +To delete the branch called my_branch: +```git branch -d my_branch```
-Push branch to remote -`git push origin branch_name` +To push a branch to remote: +```git push origin branch_name```
-Rename current branch -`git branch -m new_name` +To rename a current branch: +```git branch -m new_name```
-Merge branch \_a into branch_b -`git checkout branch_b` -`git merge branch_a` +To merge branch _a into branch_b: +```git checkout branch_b``` +```git merge branch_a```
-Abort the current merge -`git merge --abort` +To abort the current merge: +```git merge --abort```
-Tag the current commit -`git tag my_tag` +To tag the current commit: +```git tag my_tag```
-Discard all local commits and changes -`git reset --hard origin/` +To discard all local commits and changes: +```git reset --hard origin/```
### πŸ‘› Make a change - -Stages the file, ready for commit -`git add [file]` +To stage the file, ready for commit: +```git add [file]```
-Stage all changed files, ready for commit -`git add .` +To stage all changed files, ready for commit: +```git add .```
-Commit all staged files to the versioned history -`git commit -m "commit message"` +To commit all staged files to the versioned history: +```git commit -m "commit message"```
-Commit all your tracked files to the versioned history -`git commit -am "commit message` +To commit all your tracked files to the versioned history: +```git commit -am "commit message```
-Set the executable flag to an file foo.sh -`git update-index --chmod=+x foo.sh` +To set the executable flag to a file foo.sh: +```git update-index --chmod=+x foo.sh```
-Unstages the file, keeping the file changes -`git reset [file]` +To unstaged the file, keeping the file changes: +```git reset [file]```
-Revert everything to the last commit -`git reset --hard` +To revert everything to the last commit: +```git reset --hard```
-Overwrite commit history with your local history (force push): -`git push --force` +To overwrite commit history with your local history (force push): +```git push --force```
-Reset remote branch to specific commit (danger: use only if not distributed to other people before): -`git reset --hard && git push -f origin ` +To reset remote branch to specific commit (danger: use only if not distributed to other people before): +```git reset --hard && git push -f origin ```
### 🚰 Synchronize - -Get the latest changes from the origin (no merge) -`git fetch` +To get the latest changes from the origin (no merge): +```git fetch```
-Fetch the latest changes from the origin and merge -`git pull` +To fetch the latest changes from the origin and merge: +```git pull```
-Fetch the latest changes from the origin and rebase -`git pull --rebase` +To fetch the latest changes from the origin and rebase: +```git pull --rebase```
-Push local changes to the origin -`git push` +To push local changes to the origin: +```git push```
- ### 🧾 Logs and History - -Show commit history in single lines -`git log --oneline` +To show commit history in single lines: +```git log --oneline```
-Show commit history for the last N commits -`git log -2` +To show the commit history for the last N commits: +```git log -2```
-Show commit history for the last N commits with diff -`git log -p -2` +To show commit history for the last N commits with diff: +```git log -p -2```
-Show reflog history for emergency actions -`git reflog` +To show reflog history for emergency actions: +```git reflog```
-Show all local file changes in the working tree -`git diff` +To show all local file changes in the working tree: +```git diff```
-Show changes made to a file -`git diff myfile` +To show changes made to a file: +```git diff myfile```
-Show who changed what & when in a file -`git blame myfile` +To show who changed what & when in a file: +```git blame myfile```
-Show remote branches and their mapping to local -`git remote show origin` +To show remote branches and their mapping to local: +```git remote show origin```
- ### 🧹 Cleanup - -Delete all untracked files -`git clean -f` +To delete all untracked files: +```git clean -f```
-Delete all untracked files and directories -`git clean -df` +To delete all untracked files and directories: +```git clean -df```
-Undo local modifications to all files -`git checkout -- ` +To undo local modifications to all files: +```git checkout -- ```
-Unstages a file -`git reset HEAD myfile` +To unstaged a file: +```git reset HEAD myfile```
-Undo local modifications to a file and stage it -`git checkout -- myfile` -`git add myfile` +To undo local modifications to a file and stage it: +```git checkout -- myfile``` +```git add myfile```
-Find the commit that introduced a bug -`git bisect start` -`git bisect bad` -`git bisect good ` +To find the commit that introduced a bug: +```git bisect start``` +```git bisect bad``` +```git bisect good ```
### πŸ“¦ Submodules -Initialize submodules -`git submodule init` -
-Add a submodule -`git submodule add ` +To add a submodule: +```git submodule add ```
-Update a submodule -`git submodule update --remote` +To update a submodule: +```git submodule update --remote```
-Execute a command in each submodule -`git submodule foreach ` +To remove a submodule: +```git submodule deinit -f -- submodule_name``` +```git rm -f submodule_name``` +```git rm -f .gitmodules```
-Remove a submodule -`git submodule deinit -f -- submodule_name` -`git rm -f submodule_name` -`git rm -f .gitmodules` -
- ### πŸ“¦ Subtrees -Add a subtree -`git subtree add --prefix=folder_name ` +To add a subtree: +```git subtree add --prefix=folder_name ```
-Update a subtree -`git subtree pull --prefix=folder_name ` +To update a subtree: +```git subtree pull --prefix=folder_name ```
-Remove a subtree -`git subtree split --prefix=folder_name` -`git rm -rf folder_name` -`git commit -m "Remove folder_name"` +To remove a subtree: +```git subtree split --prefix=folder_name``` +```git rm -rf folder_name``` +```git commit -m "Remove folder_name"```
### πŸ—£Help -`git help -a` and `git help -g` list available subcommands and some -concept guides. See `git help ` or `git help ` +```git help -a``` and ```git help -g``` list available subcommands and some +concept guides. See ```git help ``` or ```git help ``` to read about a specific subcommand or concept. -See `git help git` for an overview of the system. -
- -### πŸ“¦Stash - -Stash Changes with a message -`git stash save "message"` -
-List all stashes -`git stash list` -
-Apply the most recent stash and remove it from the stash list. -`git stash pop` +See ```git help git``` for an overview of the system.
## Git Resources - You should check some of these Git resources as they would be amazing for your journey. You will master Git with these resources: #### ⭐ [Oh My Git](https://ohmygit.org/) - This is an open-source card game that is dedicated to teaching important git commands. There's even an integrated terminal for you to test any git command you wish. Their graphics are nothing fancy but it helps with learning visually. #### ⭐ [The Odin Project](https://www.theodinproject.com/lessons/foundations-git-basics) - This site provides free full-stack courses that are maintained by the open-source community. They have two git courses that are well worth your attention. #### ⭐ [Learn Git Branching](https://learngitbranching.js.org/) - Branching is an important topic in Git. There's no better way to learn it than this interactive game. Run commands with their built-in terminal and let their graphics explain the rest. #### ⭐ [Git Tutorial by Atlasian](https://www.atlassian.com/git/tutorials) - Become a git guru with the help of Atlassian tutorials. Atlassian has done a fantastic job with their explanations and visuals to understand git. This is one of the top resources for learning Git. #### ⭐ [Git Immersion](https://gitimmersion.com/) - Learn all the fundamentals of Git with this guided tour. This resource explains every important Git command while you execute them on your local machine. #### ⭐ [Visual Git Reference](https://marklodato.github.io/visual-git-guide/index-en.html) - I'm a big believer that visual aids help you better understand and remember information. Which is why this resource is a must-see. Their diagrams and explanations are top-tier. #### ⭐ [GitHub Minesweeper](https://profy.dev/project/github-minesweeper) - Get a dose of nostalgia with this one! Learn on-the-job Git workflow while playing minesweeper with another player. So much fun you'll forget you're even learning. ## Are you more of an extensive reader, we got you! Here is GitHub's own GIT Cheatsheet for you πŸ“— - - [GitHub's GIT Cheatsheet](https://github.com/MrKrishnaAgarwal/Git-CheatSheet/blob/main/git-cheat-sheet-education.pdf) For more in-depth reading - you should check Git Notes for Professionals πŸ“• - - [Git Notes for Professionals by GoalKicker](https://goalkicker.com/GitBook/GitNotesForProfessionals.pdf) ## Want to learn Git more interactively? From cb94b9be780241b9d9dc0092d6db4aafa26bd337 Mon Sep 17 00:00:00 2001 From: Krishna Agarwal Date: Sun, 15 Oct 2023 00:34:06 +0530 Subject: [PATCH 3/4] fix: broken contributor link Signed-off-by: Krishna Agarwal --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 85764e8..8d43a36 100644 --- a/README.md +++ b/README.md @@ -303,8 +303,7 @@ This project is licensed under the MIT License - see the [LICENSE](/LICENSE) fil
Sushil Poudel

πŸ’»
Gurnav Chaudhary

πŸ’»
Swati Aggrawal

πŸ’» - -
Ahmed Shaikh

πŸ’» +
Ahmed Shaikh

πŸ’» From 883d3eb12bf71a3b368ab78b09ba3b4c1c0086cb Mon Sep 17 00:00:00 2001 From: Krishna Agarwal Date: Mon, 23 Oct 2023 12:53:38 +0530 Subject: [PATCH 4/4] re-added stash section Signed-off-by: Krishna Agarwal --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 8d43a36..2dfdb0c 100644 --- a/README.md +++ b/README.md @@ -229,6 +229,19 @@ To remove a subtree: ```git commit -m "Remove folder_name"```
+### πŸ“¦Stash + +Stash Changes with a message +`git stash save "message"` +
+List all stashes +`git stash list` +
+Apply the most recent stash and remove it from the stash list. +`git stash pop` + +
+ ### πŸ—£Help ```git help -a``` and ```git help -g``` list available subcommands and some