diff --git a/snippet-template.md b/snippet-template.md index 83ad7b5fb..d0f2fde06 100644 --- a/snippet-template.md +++ b/snippet-template.md @@ -9,11 +9,11 @@ Explain briefly what the snippet does. - Use bullet points for your snippet's explanation. - Try to explain everything briefly but clearly. -```sh +```shell git command [--option] ``` -```sh +```shell git command some-branch --quiet # Output of running command on `some-branch` ``` diff --git a/snippets/add-submodule.md b/snippets/add-submodule.md index 186f9e36a..5dab25fdc 100644 --- a/snippets/add-submodule.md +++ b/snippets/add-submodule.md @@ -7,11 +7,11 @@ Adds a new submodule to the repository. - Use `git submodule add ` to add a new submodule from `` to ``. -```sh +```shell git submodule add ``` -```sh +```shell git submodule add https://github.com/30-seconds/30-seconds-of-code ./30code # Creates the directory `30code` containing the submodule from # "https://github.com/30-seconds/30-seconds-of-code" diff --git a/snippets/apply-latest-stash.md b/snippets/apply-latest-stash.md index 266417372..632c256db 100644 --- a/snippets/apply-latest-stash.md +++ b/snippets/apply-latest-stash.md @@ -7,10 +7,10 @@ Applies the latest stash. - Use `git stash apply` to apply the latest stash. -```sh +```shell git stash apply ``` -```sh +```shell git stash apply # Applies the latest stash ``` diff --git a/snippets/apply-stash.md b/snippets/apply-stash.md index bd8d7acbc..a6a6a3099 100644 --- a/snippets/apply-stash.md +++ b/snippets/apply-stash.md @@ -7,10 +7,10 @@ Applies a specific stash. - Use `git stash apply ` to apply the given ``. -```sh +```shell git stash apply ``` -```sh +```shell git stash apply stash@{1} # Applies `stash@{1}` ``` diff --git a/snippets/autocorrect.md b/snippets/autocorrect.md index 7e4969f58..8ab5086d0 100644 --- a/snippets/autocorrect.md +++ b/snippets/autocorrect.md @@ -7,11 +7,11 @@ Configures git to autocorrect mistyped commands. - Use `git config --global help.autocorrect 1` to enable git's autocorrect. -```sh +```shell git config --global help.autocorrect 1 ``` -```sh +```shell git config --global help.autocorrect 1 git sttaus # Runs `git status` instead ``` diff --git a/snippets/automatic-find-commit-with-bug.md b/snippets/automatic-find-commit-with-bug.md index ac465e76a..523fb61d8 100644 --- a/snippets/automatic-find-commit-with-bug.md +++ b/snippets/automatic-find-commit-with-bug.md @@ -11,7 +11,7 @@ Uses a binary search algorithm and a given script to find which commit in histor - Use `git bisect run ` to run the given `` on each subsequent commit to find which commit introduce the bug. - Use `git bisect reset` to reset to the original branch. You can optionally specify a `` to reset to. -```sh +```shell git bisect start git bisect good git bisect bad @@ -19,7 +19,7 @@ git bisect run git bisect reset [] ``` -```sh +```shell git bisect start git bisect good 3050fc0de git bisect bad c191f90c7 diff --git a/snippets/branches-containing-commit.md b/snippets/branches-containing-commit.md index b24e14e2f..b4c5626a2 100644 --- a/snippets/branches-containing-commit.md +++ b/snippets/branches-containing-commit.md @@ -7,11 +7,11 @@ Prints all the branches containing a specific commit. - Use `git branch --contains ` to see a list of all branches containing ``. -```sh +```shell git branch --contains ``` -```sh +```shell git branch --contains 3050fc0d3 # patch-1 # patch-2 diff --git a/snippets/branches-not-containing-commit.md b/snippets/branches-not-containing-commit.md index af4bb5fdd..816494a28 100644 --- a/snippets/branches-not-containing-commit.md +++ b/snippets/branches-not-containing-commit.md @@ -7,11 +7,11 @@ Prints all the branches not containing a specific commit. - Use `git branch --no-contains ` to see a list of all branches not containing ``. -```sh +```shell git branch --no-contains ``` -```sh +```shell git branch --no-contains 3050fc0d3 # patch-3 # patch-4 diff --git a/snippets/change-remote-url.md b/snippets/change-remote-url.md index 826549b4a..d42629843 100644 --- a/snippets/change-remote-url.md +++ b/snippets/change-remote-url.md @@ -7,11 +7,11 @@ Changes the URL of the remote repository. - Use `git remote set-url origin ` to change the URL of the remote repository to ``. -```sh +```shell git remote set-url origin ``` -```sh +```shell git remote set-url origin https://github.com/30-seconds/30-seconds-of-code # The remote URL is now "https://github.com/30-seconds/30-seconds-of-code" ``` diff --git a/snippets/clone-missing-submodules.md b/snippets/clone-missing-submodules.md index 0f10f4735..6c6a2b6b6 100644 --- a/snippets/clone-missing-submodules.md +++ b/snippets/clone-missing-submodules.md @@ -7,11 +7,11 @@ Clones missing submodules and checks out commits. - Use `git submodule update --init --recursive` to clone missing submodules and checkout commits. -```sh +```shell git submodule update --init --recursive ``` -```sh +```shell git submodule update --init --recursive # Clones missing submodules and checks out commits ``` diff --git a/snippets/clone-repo.md b/snippets/clone-repo.md index d04f51c8a..04e2ea834 100644 --- a/snippets/clone-repo.md +++ b/snippets/clone-repo.md @@ -8,11 +8,11 @@ Clones an existing repository, creating a local copy of it. - Use `git clone ` to clone an existing repository from `` to a local directory. The directory's name will be based on the name of the cloned repository. - Alternatively, use `git clone []` to clone the repository into the specified local ``. -```sh +```shell git clone [] ``` -```sh +```shell git clone https://github.com/30-seconds/30-seconds-of-code.git # Clones the repository in a new directory named '30-seconds-of-code' cd 30-seconds-of-code diff --git a/snippets/commit-set-author.md b/snippets/commit-set-author.md index 337e7d903..04eb47ce2 100644 --- a/snippets/commit-set-author.md +++ b/snippets/commit-set-author.md @@ -8,11 +8,11 @@ Creates a new commit by the specified author. - Use `git commit -m ` to create a new commit with the specified ``. - Use the `--author` option to change the `` and `` of the commit's author. -```sh +```shell git commit -m --author=" " ``` -```sh +```shell # Make some changes to files git add . git commit -m "Fix the network bug" --author="Duck Quackers " diff --git a/snippets/commit-template.md b/snippets/commit-template.md index e39ebaec2..ecd93645d 100644 --- a/snippets/commit-template.md +++ b/snippets/commit-template.md @@ -7,11 +7,11 @@ Sets up a commit message template for the current repository. - Use `git config commit.template ` to specify `` as the commit message template for the current repository. -```sh +```shell git config commit.template ``` -```sh +```shell git config commit.template "commit-template" # Sets "commit-template" as the commit message template ``` diff --git a/snippets/commit-without-hooks.md b/snippets/commit-without-hooks.md index 1d4c99025..c8612689b 100644 --- a/snippets/commit-without-hooks.md +++ b/snippets/commit-without-hooks.md @@ -7,11 +7,11 @@ Creates a new commit skipping the pre-commit and commit-msg hooks. - Use `git commit --no-verify -m ` to commit staged changes without running git hooks. -```sh +```shell git commit --no-verify -m ``` -```sh +```shell # Make some changes to files, ones that your precommit hook might not allow git add . git commit --no-verify -m "Unsafe commit" diff --git a/snippets/config-user.md b/snippets/config-user.md index ccf14009e..328128570 100644 --- a/snippets/config-user.md +++ b/snippets/config-user.md @@ -9,12 +9,12 @@ Configures user information for git. - Use `git config user.name ` to set the user's name for the current repository. - You can use the `--global` flag to configure global user information. -```sh +```shell git config [--global] user.email git config [--global] user.name ``` -```sh +```shell git config user.email "cool.duck@qua.ck" git config user.name "Duck Quackers" # Configures user for current repository diff --git a/snippets/copy-file-from-branch.md b/snippets/copy-file-from-branch.md index a929d29cf..d3ad88753 100644 --- a/snippets/copy-file-from-branch.md +++ b/snippets/copy-file-from-branch.md @@ -7,11 +7,11 @@ Copies a file from another branch to the current branch. - Use `git checkout ` to copy the specified `` from the specified ``. -```sh +```shell git checkout ``` -```sh +```shell git checkout patch-2 git checkout patch-1 "30seconds.txt" # `patch-2` branch now contains the 30seconds.txt file from `patch-1` diff --git a/snippets/create-branch.md b/snippets/create-branch.md index c4ed34ef2..055943b15 100644 --- a/snippets/create-branch.md +++ b/snippets/create-branch.md @@ -9,11 +9,11 @@ Creates and switches to a new branch, optionally setting up a remote tracking br - You can optionally add `-t /` to set up a remote tracking branch for the newly created branch. - Note: You can alternatively use `git branch [-t /]` and then `git checkout ` separately. -```sh +```shell git checkout -b [-t /] ``` -```sh +```shell git checkout -b patch-1 # Local branch, without a remote tracking branch diff --git a/snippets/create-commit.md b/snippets/create-commit.md index 53a18f22d..8d6833002 100644 --- a/snippets/create-commit.md +++ b/snippets/create-commit.md @@ -7,11 +7,11 @@ Creates a new commit containing the staged changes. - Use `git commit -m ` to create a new commit with the specified ``. -```sh +```shell git commit -m ``` -```sh +```shell # Make some changes to files git add . git commit -m "Fix the network bug" diff --git a/snippets/create-empty-commit.md b/snippets/create-empty-commit.md index d803ca84c..f3e2ecdee 100644 --- a/snippets/create-empty-commit.md +++ b/snippets/create-empty-commit.md @@ -7,11 +7,11 @@ Creates an empty commit. - Use `git commit --allow-empty -m ` to create an empty commit with the provided ``. -```sh +```shell git commit --allow-empty -m ``` -```sh +```shell git commit --allow-empty -m "Empty commit" # Creates an empty commit with the message "Empty commit" ``` diff --git a/snippets/create-fixup-commit.md b/snippets/create-fixup-commit.md index 1db29948b..dcdc3b1a1 100644 --- a/snippets/create-fixup-commit.md +++ b/snippets/create-fixup-commit.md @@ -8,11 +8,11 @@ Creates a fixup commit that can be autosquashed in the next rebase. - Use `git commit --fixup ` to create a fixup commit for the specified ``. - After running `git rebase --autosquash`, fixup commits will be automatically squashed into the commits they reference. -```sh +```shell git commit --fixup ``` -```sh +```shell git add . git commit --fixup 3050fc0de # Created a fixup commit for `3050fc0de` diff --git a/snippets/create-repo.md b/snippets/create-repo.md index 774e43cba..c6a462c9a 100644 --- a/snippets/create-repo.md +++ b/snippets/create-repo.md @@ -10,11 +10,11 @@ Initializes a new git repository, setting up all the configuration files needed - Note: Running `git init` in an existing repository is safe. - Note: You only need to run `git init` once per repository. -```sh +```shell git init [] ``` -```sh +```shell cd ~/my_project git init # Initializes a repo in ~/my_project diff --git a/snippets/current-branch-name.md b/snippets/current-branch-name.md index 6aac16ff9..c814a5139 100644 --- a/snippets/current-branch-name.md +++ b/snippets/current-branch-name.md @@ -7,11 +7,11 @@ Prints the current branch name. - Use `git rev-parse --abbrev-ref HEAD` to print the name of the current branch. -```sh +```shell git rev-parse --abbrev-ref HEAD ``` -```sh +```shell git checkout patch-1 git rev-parse --abbrev-ref HEAD # Prints `patch-1` ``` diff --git a/snippets/delete-branch.md b/snippets/delete-branch.md index 0f21c4938..1a9b57a8c 100644 --- a/snippets/delete-branch.md +++ b/snippets/delete-branch.md @@ -7,11 +7,11 @@ Deletes a local branch. - Use `git branch -d ` to delete the specified local ``. -```sh +```shell git branch -d ``` -```sh +```shell git checkout master git branch -d patch-1 # Deletes the `patch-1` local branch ``` diff --git a/snippets/delete-detached-branches.md b/snippets/delete-detached-branches.md index bcf24a33f..4b5b2c023 100644 --- a/snippets/delete-detached-branches.md +++ b/snippets/delete-detached-branches.md @@ -8,11 +8,11 @@ Deletes all detached branches. - Use `git fetch --all --prune` to garbage collect any detached branches. - This is especially useful if the remote repository is set to automatically delete merged branches. -```sh +```shell git fetch --all --prune ``` -```sh +```shell git checkout master git branch # master diff --git a/snippets/delete-merged-branches.md b/snippets/delete-merged-branches.md index a338ddfaf..ee189cad6 100644 --- a/snippets/delete-merged-branches.md +++ b/snippets/delete-merged-branches.md @@ -9,11 +9,11 @@ Deletes all local merged branches. - Use the pipe operator (`|`) to pipe the output and `grep -v "(^\*|)"` to exclude the current and the target ``. - Use the pipe operator (`|`) to pipe the output and `xargs git branch -d` to delete all of the found branches. -```sh +```shell git branch --merged | grep -v "(^\*|)" | xargs git branch -d ``` -```sh +```shell git checkout master git branch # master diff --git a/snippets/delete-remote-branch.md b/snippets/delete-remote-branch.md index dec8164b1..5800592e7 100644 --- a/snippets/delete-remote-branch.md +++ b/snippets/delete-remote-branch.md @@ -7,11 +7,11 @@ Deletes a remote branch. - Use `git push -d ` to delete the specified remote `` on the given ``. -```sh +```shell git push -d ``` -```sh +```shell git checkout master git push -d origin patch-1 # Deletes the `patch-1` remote branch ``` diff --git a/snippets/delete-stash.md b/snippets/delete-stash.md index 8af9ec739..127261846 100644 --- a/snippets/delete-stash.md +++ b/snippets/delete-stash.md @@ -7,10 +7,10 @@ Deletes a specific stash. - Use `git stash drop ` to delete the given ``. -```sh +```shell git stash drop ``` -```sh +```shell git stash drop stash@{1} # Deletes `stash@{1}` ``` diff --git a/snippets/delete-stashes.md b/snippets/delete-stashes.md index 3eb7d07ee..2a037fce2 100644 --- a/snippets/delete-stashes.md +++ b/snippets/delete-stashes.md @@ -7,11 +7,11 @@ Deletes all stashes. - Use `git stash clear` to delete all stashes. -```sh +```shell git stash clear ``` -```sh +```shell git stash clear # Deletes all stashes ``` diff --git a/snippets/delete-submodule.md b/snippets/delete-submodule.md index f4caaa4f8..261b79912 100644 --- a/snippets/delete-submodule.md +++ b/snippets/delete-submodule.md @@ -9,13 +9,13 @@ Deletes a submodule from the repository. - Use `rm -rf .git/modules/` to remove the directory of the submodule. - Use `git rm -f ` to remove the working tree of the submodule. -```sh +```shell git submodule deinit -f -- rm -rf .git/modules/ git rm -f ``` -```sh +```shell git submodule deinit -f -- 30code rm -rf .git/modules/30code git rm -f 30code diff --git a/snippets/difference-between-branches.md b/snippets/difference-between-branches.md index 5d416a334..1bc764cef 100644 --- a/snippets/difference-between-branches.md +++ b/snippets/difference-between-branches.md @@ -7,11 +7,11 @@ Displays the difference between two branches. - Use `git diff .. ` to view the difference between `` and ``. -```sh +```shell git diff .. ``` -```sh +```shell git diff patch-1..patch-2 # Displays the difference between branches `patch-1` and `patch-2` ``` diff --git a/snippets/discard-uncommitted.md b/snippets/discard-uncommitted.md index 1a231c5b3..03cef533d 100644 --- a/snippets/discard-uncommitted.md +++ b/snippets/discard-uncommitted.md @@ -7,11 +7,11 @@ Discards all uncommitted changes to the current branch. - Use `git reset --hard HEAD` to reset the local directory to match the latest commit and discard all unstaged changes. -```sh +```shell git reset --hard HEAD ``` -```sh +```shell git reset --hard HEAD # Discards all unstaged changes ``` diff --git a/snippets/discard-untracked.md b/snippets/discard-untracked.md index b8d6d406e..b6099c184 100644 --- a/snippets/discard-untracked.md +++ b/snippets/discard-untracked.md @@ -7,11 +7,11 @@ Discards all untracked changes to the current branch. - Use `git clean -f -d` to discard all untracked changes to the current branch. -```sh +```shell git clean -f -d ``` -```sh +```shell git clean -f -d # Discards all untracked changes ``` diff --git a/snippets/edit-config.md b/snippets/edit-config.md index c1a8500d3..9909fd3dd 100644 --- a/snippets/edit-config.md +++ b/snippets/edit-config.md @@ -7,11 +7,11 @@ Opens the git configuration file in the git text editor. - Use `git config --global -e` to open the git configuration file in the git text editor. -```sh +```shell git config --global -e ``` -```sh +```shell git config --global -e # Opens the git configuration file in the default git text editor ``` diff --git a/snippets/fetch-changes.md b/snippets/fetch-changes.md index a34bb2671..417304ac5 100644 --- a/snippets/fetch-changes.md +++ b/snippets/fetch-changes.md @@ -7,10 +7,10 @@ Fetches the latest changes from the remote. - Use `git fetch` to get the latest changes from the remote, without applying them. -```sh +```shell git fetch ``` -```sh +```shell git fetch # Fetches the latest updates from the remote ``` diff --git a/snippets/find-lost-files.md b/snippets/find-lost-files.md index 39600189f..901048374 100644 --- a/snippets/find-lost-files.md +++ b/snippets/find-lost-files.md @@ -8,11 +8,11 @@ Prints a list of lost files and commits. - Use `git fsck --lost-found` to print a list of all dangling objects. - All appropriate files will be extracted into the `.git/lost-found` directory. -```sh +```shell git fsck --lost-found ``` -```sh +```shell git fsck --lost-found # dangling commit 3050fc0de # dangling blob 807e3fa41 diff --git a/snippets/force-update-remote-branch.md b/snippets/force-update-remote-branch.md index bb8a626d5..4dca1a016 100644 --- a/snippets/force-update-remote-branch.md +++ b/snippets/force-update-remote-branch.md @@ -8,11 +8,11 @@ Forces an update of the remote branch adter rewriting the history locally. - Use `git push -f` to force update the remote branch, overwriting it using the local branch's changes. - This operation is necessary anytime your local and remote repository diverge. -```sh +```shell git push -f ``` -```sh +```shell git checkout patch-1 git pull git rebase master diff --git a/snippets/interactive-rebase.md b/snippets/interactive-rebase.md index 08d2b7716..e3504c638 100644 --- a/snippets/interactive-rebase.md +++ b/snippets/interactive-rebase.md @@ -10,11 +10,11 @@ Performs an interactive rebase. - You can optionally use the `--autosquash` option to automatically squash fixup commits. - If you have merge conflicts or stop to make changes, you can continue the rebase when ready using `git rebase --continue` or abort it using `git rebase --abort`. -```sh +```shell git rebase -i [--autosquash] ``` -```sh +```shell git rebase -i 3050fc0de # Performs an interactive rebase starting from `3050fc0de` diff --git a/snippets/line-endings.md b/snippets/line-endings.md index 4aa3a5d03..507ad61fc 100644 --- a/snippets/line-endings.md +++ b/snippets/line-endings.md @@ -8,10 +8,10 @@ Configures the line endings for a repository. - Use `git config core.eol [lf | crlf]` to configure the line endings. - `lf` is the UNIX line ending (`\n`), whereas `crlf` is the DOS line ending (`\r\n`). -```sh +```shell git config core.eol [lf | crlf] ``` -```sh +```shell git config core.eol lf # Configured to use UNIX line endings ``` diff --git a/snippets/list-aliases.md b/snippets/list-aliases.md index 338666f44..1251b2c27 100644 --- a/snippets/list-aliases.md +++ b/snippets/list-aliases.md @@ -9,11 +9,11 @@ Prints a list of all git aliases. - Use the pipe operator (`|`) to pipe the output and `grep alias` to only keep aliases. - Use the pipe operator (`|`) to pipe the output and `sed 's/^alias\.//g'` to remove the `alias.` part from each alias. -```sh +```shell git config -l | grep alias | sed 's/^alias\.//g' ``` -```sh +```shell git config -l | grep alias | sed 's/^alias\.//g' # st=status # co=checkout diff --git a/snippets/list-stashes.md b/snippets/list-stashes.md index ad338d778..bcadcbfe6 100644 --- a/snippets/list-stashes.md +++ b/snippets/list-stashes.md @@ -7,11 +7,11 @@ Displays a list of all stashes. - Use `git stash list` to view a list of all stashes. -```sh +```shell git stash list ``` -```sh +```shell git stash list # stash@{0}: WIP on patch-1: ee52eda Fix network bug ``` diff --git a/snippets/manual-find-commit-with-bug.md b/snippets/manual-find-commit-with-bug.md index 465002499..a693debe7 100644 --- a/snippets/manual-find-commit-with-bug.md +++ b/snippets/manual-find-commit-with-bug.md @@ -11,7 +11,7 @@ Uses a binary search algorithm to manually find which commit in history introduc - Use `git bisect (bad | good)` marking each subsequent commit as "good" or "bad" depending if it has the bug or not. - Use `git bisect reset` to reset to the original branch. You can optionally specify a `` to reset to. -```sh +```shell git bisect start git bisect good git bisect bad @@ -19,7 +19,7 @@ git bisect (bad | good) git bisect reset [] ``` -```sh +```shell git bisect start git bisect good 3050fc0de git bisect bad c191f90c7 diff --git a/snippets/merge-branch-merge-commit.md b/snippets/merge-branch-merge-commit.md index d2ae0216e..d0039f11e 100644 --- a/snippets/merge-branch-merge-commit.md +++ b/snippets/merge-branch-merge-commit.md @@ -8,12 +8,12 @@ Merges a branch into the current branch, creating a merge commit. - Use `git checkout ` to switch to the branch into which you want to merge. - Use `git merge --no-ff -m ` to merge a branch into the current branch, creating a merge commit with the specified ``. -```sh +```shell git checkout git merge --no-ff -m ``` -```sh +```shell git checkout master git merge --no-ff -m "Merge patch-1" patch-1 # Merges the `patch-1` branch into `master` and creates a commit diff --git a/snippets/merge-branch.md b/snippets/merge-branch.md index f870e5c9c..70e9a9c38 100644 --- a/snippets/merge-branch.md +++ b/snippets/merge-branch.md @@ -8,12 +8,12 @@ Merges a branch into the current branch. - Use `git checkout ` to switch to the branch into which you want to merge. - Use `git merge ` to merge a branch into the current branch. -```sh +```shell git checkout git merge ``` -```sh +```shell git checkout master git merge patch-1 # Merges the `patch-1` branch into `master` ``` diff --git a/snippets/move-commits-to-branch.md b/snippets/move-commits-to-branch.md index fa241e7ae..18b9d06e9 100644 --- a/snippets/move-commits-to-branch.md +++ b/snippets/move-commits-to-branch.md @@ -10,13 +10,13 @@ Moves local commits from the `master` branch to a new branch. - Use `git checkout ` to switch to the new branch. - Only works if the changes have only been committed locally and not pushed to the remote. -```sh +```shell git branch git reset HEAD~ --hard git checkout ``` -```sh +```shell git checkout master git add . git commit -m "Fix network bug" diff --git a/snippets/optimize-repository.md b/snippets/optimize-repository.md index 8694cbe82..12ff2ae00 100644 --- a/snippets/optimize-repository.md +++ b/snippets/optimize-repository.md @@ -7,10 +7,10 @@ Optimizes the local repository. - Use `git gc --prune=now --aggressive` to garbage collect loose objects. -```sh +```shell git gc --prune=now --aggressive ``` -```sh +```shell git gc --prune=now --aggressive # Optimizes the local repository ``` diff --git a/snippets/pick-commits.md b/snippets/pick-commits.md index c1cb8fb54..d6e0a599f 100644 --- a/snippets/pick-commits.md +++ b/snippets/pick-commits.md @@ -9,11 +9,11 @@ Applies the changes introduced by one or more commits. - Use `git cherry-pick ...` to pick changes from all space-separated commits. - Use `git cherry-pick ..` to pick changes from a range of commits. -```sh +```shell git cherry-pick (... | ..) ``` -```sh +```shell git cherry-pick 3050fc0de # Picks changes from the commit `3050fc0de` git cherry-pick 3050fc0de c191f90c7 diff --git a/snippets/pull-all-submodules.md b/snippets/pull-all-submodules.md index c2bf7c127..bed3bbdfa 100644 --- a/snippets/pull-all-submodules.md +++ b/snippets/pull-all-submodules.md @@ -7,11 +7,11 @@ Pulls all submodules from their respective remotes. - Use `git submodule update --recursive --remote` to pull all submodules from their respective remotes. -```sh +```shell git submodule update --recursive --remote ``` -```sh +```shell git submodule update --recursive --remote # Pulls all submodules from their respective remotes ``` diff --git a/snippets/pull-changes.md b/snippets/pull-changes.md index a05c0a7af..780e88b22 100644 --- a/snippets/pull-changes.md +++ b/snippets/pull-changes.md @@ -7,11 +7,11 @@ Pulls the latest changes from the remote tracking branch. - Use `git pull` to fetch and apply the latest changes from the remote. -```sh +```shell git pull ``` -```sh +```shell # Assuming the remote `patch-1` branch is ahead of the local one git checkout patch-1 git pull # The local `patch-1` branch is now up to date with the remote branch diff --git a/snippets/purge-file.md b/snippets/purge-file.md index a8e4fd124..1a29daa03 100644 --- a/snippets/purge-file.md +++ b/snippets/purge-file.md @@ -10,14 +10,14 @@ Completely purges a file from history. - You can optionally use `git push --force -all` to force push the changes to the remote repository. - ⚠️ **WARNING**: This is a destructive action that rewrites the history of the entire repository. Make sure you know what you are doing. -```sh +```shell git filter-branch --force --index-filter \ "git rm --cached --ignore-unmatch " \ --prune-empty --tag-name-filter cat -- --all git push --force --all ``` -```sh +```shell git filter-branch --force --index-filter \ "git rm --cached --ignore-unmatch config/apiKeys.json" \ --prune-empty --tag-name-filter cat -- --all diff --git a/snippets/push-changes.md b/snippets/push-changes.md index 61fba5c40..9c162cb5c 100644 --- a/snippets/push-changes.md +++ b/snippets/push-changes.md @@ -7,11 +7,11 @@ Pushes the current branch's changes to the remote. - Use `git push` to push the latest changes from the local branch to the remote. -```sh +```shell git fetch ``` -```sh +```shell # Assuming the local `patch-1` branch is ahead of the remote one git checkout patch-1 git push # The remote `patch-1` branch is now up to date with the local branch diff --git a/snippets/rebase-onto-branch.md b/snippets/rebase-onto-branch.md index 001266b40..557887193 100644 --- a/snippets/rebase-onto-branch.md +++ b/snippets/rebase-onto-branch.md @@ -8,12 +8,12 @@ Rebases the current branch onto another branch. - Use `git checkout ` to switch to the `` to be rebased. - Use `git rebase ` to rebase the current branch onto ``. -```sh +```shell git checkout git rebase ``` -```sh +```shell git checkout patch-1 git rebase master # `patch-1` is rebased onto `master` diff --git a/snippets/remove-file-from-commit.md b/snippets/remove-file-from-commit.md index 99d684dee..14b00b7be 100644 --- a/snippets/remove-file-from-commit.md +++ b/snippets/remove-file-from-commit.md @@ -8,12 +8,12 @@ Removes a file from the last commit without changing its message. - Use `git rm —-cached ` to remove the specified `` from the index. - Use `git commit —-amend` to update the contents of the last commit, without changing its message. -```sh +```shell git rm —-cached git commit —-amend ``` -```sh +```shell git rm —-cached "30-seconds.txt" git commit —-amend # Removes `30-seconds.txt` from the last commit diff --git a/snippets/rename-branch.md b/snippets/rename-branch.md index 1b4d01e46..56160aa75 100644 --- a/snippets/rename-branch.md +++ b/snippets/rename-branch.md @@ -7,11 +7,11 @@ Renames a local branch. - Use `git branch -m ` to rename `` to ``. -```sh +```shell git branch -m ``` -```sh +```shell git checkout master git branch -m patch-1 patch-2 # Renames `patch-1` to `patch-2` diff --git a/snippets/rename-remote-branch.md b/snippets/rename-remote-branch.md index 00833d22a..342b61d93 100644 --- a/snippets/rename-remote-branch.md +++ b/snippets/rename-remote-branch.md @@ -10,14 +10,14 @@ Renames a branch both locally and on the remote. - Use `git checkout ` to switch to the renamed branch. - Use `git push origin -u ` to set `` as the remote branch for the renamed branch. -```sh +```shell git branch -m git push origin --delete git checkout git push origin -u ``` -```sh +```shell git checkout master git branch -m patch-1 patch-2 # Renamed the local branch to `patch-2` git push origin --delete patch-1 diff --git a/snippets/reset-master.md b/snippets/reset-master.md index 1820067a3..79e7e23c1 100644 --- a/snippets/reset-master.md +++ b/snippets/reset-master.md @@ -9,13 +9,13 @@ Resets the local `master` branch to match the one on the remote. - Use `git checkout master` to switch to the `master` branch. - Use `git reset --hard origin/master` to reset the local `master` branch to match the one on the remote. -```sh +```shell git fetch origin git checkout master git reset --hard origin/master ``` -```sh +```shell git fetch origin git checkout master git reset --hard origin/master diff --git a/snippets/restore-deleted-file.md b/snippets/restore-deleted-file.md index bc256d62d..431df8ef0 100644 --- a/snippets/restore-deleted-file.md +++ b/snippets/restore-deleted-file.md @@ -7,11 +7,11 @@ Restores a file deleted in a specific commit. - Use `git checkout ^ -- ` to restore the specified `` deleted in the specified ``. -```sh +```shell git checkout ^ -- ``` -```sh +```shell # "30seconds.txt" was deleted in the commit `3050fc0de` git checkout 3050fc0de^ -- "30seconds.txt" # Restores the 30seconds.txt file diff --git a/snippets/rewind-n-commits.md b/snippets/rewind-n-commits.md index 7dcff6683..dc85aab20 100644 --- a/snippets/rewind-n-commits.md +++ b/snippets/rewind-n-commits.md @@ -9,11 +9,11 @@ Rewinds the current branch by a given number of commits. - This command will uncommit and unstage changes, but leave them in the working directory. - You can use the `--hard` flag to uncommit, unstage and delete changes instead. -```sh +```shell git reset [--hard] HEAD~ ``` -```sh +```shell git reset HEAD~5 # Rewinds back 5 commits but keeps changes in the working directory diff --git a/snippets/rewind-to-commit.md b/snippets/rewind-to-commit.md index e8cb58d00..093514076 100644 --- a/snippets/rewind-to-commit.md +++ b/snippets/rewind-to-commit.md @@ -9,11 +9,11 @@ Rewinds the current branch by a given number of commits. - This command will uncommit and unstage changes, but leave them in the working directory. - You can use the `--hard` flag to uncommit, unstage and delete changes instead. -```sh +```shell git reset [--hard] ``` -```sh +```shell git reset --hard 3050fc0d3 # Rewinds back to `3050fc0d3` but keeps changes in the working directory diff --git a/snippets/save-stash.md b/snippets/save-stash.md index 31cad4362..c9320e9be 100644 --- a/snippets/save-stash.md +++ b/snippets/save-stash.md @@ -9,11 +9,11 @@ Saves the current state of the working directory and index into a new stash. - You can optionally use the `-u` option to include untracked files. - You can optionally provide a `` for the stash. -```sh +```shell git stash save [-u] [] ``` -```sh +```shell git stash save # Creates a new stash diff --git a/snippets/set-text-editor.md b/snippets/set-text-editor.md index bd3c5f0f8..916e85ade 100644 --- a/snippets/set-text-editor.md +++ b/snippets/set-text-editor.md @@ -7,11 +7,11 @@ Configures the text editor used by git. - Use `git config --global core.editor ` to call `` as the git text editor. -```sh +```shell git config --global core.editor ``` -```sh +```shell git config --global core.editor "code --wait" # Sets VS Code as the git text editor ``` diff --git a/snippets/sort-branches-by-date.md b/snippets/sort-branches-by-date.md index d45fc4072..f4fa79889 100644 --- a/snippets/sort-branches-by-date.md +++ b/snippets/sort-branches-by-date.md @@ -8,11 +8,11 @@ Prints a list of all local branches sorted by date. - Use `git branch --sort=-committerdate` to display a list of all local branches and sort them based on the date of their last commit. - Use arrow keys to navigate, press Q to exit. -```sh +```shell git branch --sort=-committerdate ``` -```sh +```shell git branch --sort=-committerdate # master # patch-1 diff --git a/snippets/stage-files.md b/snippets/stage-files.md index eb1c1e173..b7aa25e21 100644 --- a/snippets/stage-files.md +++ b/snippets/stage-files.md @@ -8,11 +8,11 @@ Adds files to the staging area. - Use `git add ` to add files to the staging area. - `` can be a filename or a fileglob. -```sh +```shell git add ``` -```sh +```shell git add "30seconds.txt" # Add the file `30seconds.txt` to the staging area diff --git a/snippets/switch-to-branch.md b/snippets/switch-to-branch.md index f0fecf8cc..35a7a5ab8 100644 --- a/snippets/switch-to-branch.md +++ b/snippets/switch-to-branch.md @@ -8,10 +8,10 @@ Switches to an existing branch. - Use `git checkout ` to switch to the specified branch. - Note: In newer versions of git, you can also use `git switch `. -```sh +```shell git checkout ``` -```sh +```shell git checkout patch-1 # Switches to the branch named `patch-1` ``` diff --git a/snippets/switch-to-last-branch.md b/snippets/switch-to-last-branch.md index baa21a683..f8f94ce5b 100644 --- a/snippets/switch-to-last-branch.md +++ b/snippets/switch-to-last-branch.md @@ -7,11 +7,11 @@ Switches back to the last branch. - Use `git checkout -` to switch back to the previous branch. -```sh +```shell git checkout - ``` -```sh +```shell git checkout patch-1 git checkout master git checkout - # Switches to `patch-1` diff --git a/snippets/undo-commit.md b/snippets/undo-commit.md index ba33c4259..ded0264dd 100644 --- a/snippets/undo-commit.md +++ b/snippets/undo-commit.md @@ -7,11 +7,11 @@ Undoes a specified commit without rewriting history. - Use `git revert ` to revert the specified ``, creating a new commit with the inverse of the commit's changes. -```sh +```shell git revert ``` -```sh +```shell git revert 3050fc0d3 # Reverts the commit `3050fc0d3` ``` diff --git a/snippets/undo-last-commit.md b/snippets/undo-last-commit.md index 1a3fd8676..1aded2bbe 100644 --- a/snippets/undo-last-commit.md +++ b/snippets/undo-last-commit.md @@ -7,11 +7,11 @@ Undoes the last commit without rewriting history. - Use `git revert HEAD` to revert the last commit, creating a new commit with the inverse of the commit's changes. -```sh +```shell git revert HEAD ``` -```sh +```shell git revert HEAD # Reverts the last commit ``` diff --git a/snippets/unstage-files.md b/snippets/unstage-files.md index e30682a08..ebf0e0644 100644 --- a/snippets/unstage-files.md +++ b/snippets/unstage-files.md @@ -8,11 +8,11 @@ Removes files from the staging area. - Use `git restore --staged ` to remove files from the staging area. - `` can be a filename or a fileglob. -```sh +```shell git restore --staged ``` -```sh +```shell git restore --staged "30seconds.txt" # Remove the file `30seconds.txt` from the staging area diff --git a/snippets/update-commit-contents.md b/snippets/update-commit-contents.md index 93612287a..13d26c4b2 100644 --- a/snippets/update-commit-contents.md +++ b/snippets/update-commit-contents.md @@ -7,11 +7,11 @@ Updates the last commit's contents without changing its message. - Use `git commit --amend --no-edit` to add any staged changes to the last commit, without changing its message. -```sh +```shell git commit --amend --no-edit ``` -```sh +```shell git add . git commit -m "Fix the network bug" # Edit or add files diff --git a/snippets/update-commit-message.md b/snippets/update-commit-message.md index afebe044b..d4748ad8e 100644 --- a/snippets/update-commit-message.md +++ b/snippets/update-commit-message.md @@ -7,11 +7,11 @@ Updates the last commit's message without changing its contents. - Use `git commit --amend -m ` to replace the last commit's message with the new ``. -```sh +```shell git commit --amend -m ``` -```sh +```shell git add . git commit -m "Fix the newtork bug" git commit --amend -m "Fix the network bug" diff --git a/snippets/view-all-branches.md b/snippets/view-all-branches.md index 01cb461fc..9d1c49a1f 100644 --- a/snippets/view-all-branches.md +++ b/snippets/view-all-branches.md @@ -8,11 +8,11 @@ Prints a list of all local branches. - Use `git branch` to display a list of all local branches. - Use arrow keys to navigate, press Q to exit. -```sh +```shell git branch ``` -```sh +```shell git branch # master # patch-1 diff --git a/snippets/view-changes-summary.md b/snippets/view-changes-summary.md index 84590f3ee..dd7afe9bc 100644 --- a/snippets/view-changes-summary.md +++ b/snippets/view-changes-summary.md @@ -8,11 +8,11 @@ Prints a summary of changes between two given commits. - Use `git shortlog ..` to view a summary of changes between the two given commits. - Use arrow keys to navigate, press Q to exit. -```sh +```shell git shortlog .. ``` -```sh +```shell git shortlog 3050fc0de..HEAD # Duck Quacking (2): # Fix network bug diff --git a/snippets/view-commit-graph.md b/snippets/view-commit-graph.md index 56491b0fa..b0e147b53 100644 --- a/snippets/view-commit-graph.md +++ b/snippets/view-commit-graph.md @@ -8,11 +8,11 @@ Prints a visual graph of all commits and branches in the repository. - Use `git log --pretty=oneline --graph --decorate --all` to view a visual graph of the whole repository's history. - Use arrow keys to navigate, press Q to exit. -```sh +```shell git log --pretty=oneline --graph --decorate --all ``` -```sh +```shell git log --pretty=oneline --graph --decorate --all # * 3050fc0de Fix network bug # * c191f90c7 Initial commit diff --git a/snippets/view-commits-by-author.md b/snippets/view-commits-by-author.md index 3c92c8f5d..727268404 100644 --- a/snippets/view-commits-by-author.md +++ b/snippets/view-commits-by-author.md @@ -8,11 +8,11 @@ Prints all commits by the specified author. - Use `git log --author=` to retrieve all commits by the specified ``. - Use arrow keys to navigate, press Q to exit. -```sh +```shell git log --author= ``` -```sh +```shell git log --author="Duck Quacking" # commit c191f90c7766ee6d5f24e90b552a6d446f0d02e4 # Author: 30 seconds of code diff --git a/snippets/view-commits-by-string.md b/snippets/view-commits-by-string.md index 24582610e..0af3e11a4 100644 --- a/snippets/view-commits-by-string.md +++ b/snippets/view-commits-by-string.md @@ -8,11 +8,11 @@ Prints a list of all commits that manipulated a given string. - Use `git log -S` to find all commits that manipulated the specified ``. - Use arrow keys to navigate, press Q to exit. -```sh +```shell git log -S ``` -```sh +```shell git log -S"30-seconds" # commit c191f90c7766ee6d5f24e90b552a6d446f0d02e4 # Author: 30 seconds of code diff --git a/snippets/view-commits-in-date-range.md b/snippets/view-commits-in-date-range.md index 6699de1a2..61acddb47 100644 --- a/snippets/view-commits-in-date-range.md +++ b/snippets/view-commits-in-date-range.md @@ -9,11 +9,11 @@ Prints all commits in the specified date range. - You can use only `--since=` to see all commits since a specific date or only `--until=` to view all commits up to a specific date - Use arrow keys to navigate, press Q to exit. -```sh +```shell git log [--since=] [--until=] ``` -```sh +```shell git log --since='Apr 1 2021' --until='Apr 4 2021' # commit c191f90c7766ee6d5f24e90b552a6d446f0d02e4 # Author: 30 seconds of code diff --git a/snippets/view-commits-summary-no-merges.md b/snippets/view-commits-summary-no-merges.md index 5afe46024..4ac1b9e71 100644 --- a/snippets/view-commits-summary-no-merges.md +++ b/snippets/view-commits-summary-no-merges.md @@ -7,11 +7,11 @@ Prints a short summary of all commits excluding merge commits. - Use `git log --oneline --no-merges` to list a short summary of all commits without merge commits. -```sh +```shell git log --oneline --no-merges ``` -```sh +```shell git log --oneline --no-merges # 3050fc0de Fix network bug # c191f90c7 Initial commit diff --git a/snippets/view-commits-summary.md b/snippets/view-commits-summary.md index bf57b671f..9fda48875 100644 --- a/snippets/view-commits-summary.md +++ b/snippets/view-commits-summary.md @@ -7,11 +7,11 @@ Prints a short summary of all commits. - Use `git log --oneline` to list a short summary of all commits. -```sh +```shell git log --oneline ``` -```sh +```shell git log --oneline # d540ba1ab Merge network bug fix # 3050fc0de Fix network bug diff --git a/snippets/view-differences.md b/snippets/view-differences.md index ec7bcd572..69254ae28 100644 --- a/snippets/view-differences.md +++ b/snippets/view-differences.md @@ -8,11 +8,11 @@ Displays differences between staged or unstaged changes and the last commit. - Use `git diff` to view differences between your unstaged changes and the last commit. - You can use the `--staged` option to view differences between your staged changes and the last commit instead. -```sh +```shell git diff [--staged] ``` -```sh +```shell git diff # Displays the differences between unstaged changes and the last commit diff --git a/snippets/view-last-commit.md b/snippets/view-last-commit.md index bdefdffdd..48a6d272c 100644 --- a/snippets/view-last-commit.md +++ b/snippets/view-last-commit.md @@ -8,11 +8,11 @@ Prints the last commit. - Use `git log -1` to view the last commit. - Use arrow keys to navigate, press Q to exit. -```sh +```shell git log -1 ``` -```sh +```shell git log -1 # commit c191f90c7766ee6d5f24e90b552a6d446f0d02e4 # Author: 30 seconds of code diff --git a/snippets/view-merged-branches.md b/snippets/view-merged-branches.md index bd6ada546..f05f6f140 100644 --- a/snippets/view-merged-branches.md +++ b/snippets/view-merged-branches.md @@ -8,11 +8,11 @@ Prints a list of all merged local branches. - Use `git branch -a --merged` to display a list of all merged local branches. - Use arrow keys to navigate, press Q to exit. -```sh +```shell git branch -a --merged ``` -```sh +```shell git checkout master git branch -a --merged # patch-1 diff --git a/snippets/view-remote-url.md b/snippets/view-remote-url.md index 2ffeacb4e..9b67c216c 100644 --- a/snippets/view-remote-url.md +++ b/snippets/view-remote-url.md @@ -7,11 +7,11 @@ Displays the URL of the remote repository. - Use `git config --get remote.origin.url` to view the URL of the remote repository. -```sh +```shell git config --get remote.origin.url ``` -```sh +```shell git config --get remote.origin.url # https://github.com/30-seconds/30-seconds-of-code ``` diff --git a/snippets/view-status.md b/snippets/view-status.md index dc5d314b3..e9415abd5 100644 --- a/snippets/view-status.md +++ b/snippets/view-status.md @@ -8,11 +8,11 @@ Prints the current status of the working tree. - Use `git status` to view the current status of the working tree. - You can optionally add the `-sb` flag to view the short form of the same output -```sh +```shell git status [-sb] ``` -```sh +```shell git status # On branch patch-1 # Your branch is up to date with 'origin/patch-1'. diff --git a/snippets/view-undo-history.md b/snippets/view-undo-history.md index ba59176b7..0be6076e0 100644 --- a/snippets/view-undo-history.md +++ b/snippets/view-undo-history.md @@ -12,11 +12,11 @@ Because sometimes git log doesn't cut it, especially for commands that don't sho reflog is basically your safety net after running "scary" commands like git rebase. You'll be able to see not only the commits you made, but each of the actions that led you there. -```sh +```shell git reflog ``` -```sh +```shell git reflog # b6a4f9d6ff9 (HEAD -> patch-1, origin/patch-1) HEAD@{0}: Update docs # 3050fc0de HEAD@{1}: rebase -i (finish): returning to refs/heads/patch-1