Nest all content into snippets

This commit is contained in:
Angelos Chalaris
2023-05-07 16:07:29 +03:00
parent 2ecadbada9
commit 6a45d2ec07
1240 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,23 @@
---
title: Add a submodule
type: snippet
language: git
tags: [repository,submodule]
author: chalarangelo
cover: rocky-mountains
dateModified: 2021-04-13T21:10:59+03:00
---
Adds a new submodule to the repository.
- Use `git submodule add <upstream-path> <local-path>` to add a new submodule from `<upstream-path>` to `<local-path>`.
```shell
git submodule add <upstream-path> <local-path>
```
```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"
```

View File

@ -0,0 +1,21 @@
---
title: Apply the latest stash
type: snippet
language: git
tags: [repository,stash]
author: chalarangelo
cover: palm-tree-house
dateModified: 2021-04-13T21:10:59+03:00
---
Applies the latest stash.
- Use `git stash apply` to apply the latest stash.
```shell
git stash apply <stash>
```
```shell
git stash apply # Applies the latest stash
```

View File

@ -0,0 +1,21 @@
---
title: Apply a stash
type: snippet
language: git
tags: [repository,stash]
author: chalarangelo
cover: obelisk
dateModified: 2021-04-13T21:10:59+03:00
---
Applies a specific stash.
- Use `git stash apply <stash>` to apply the given `<stash>`.
```shell
git stash apply <stash>
```
```shell
git stash apply stash@{1} # Applies `stash@{1}`
```

View File

@ -0,0 +1,22 @@
---
title: Autocorrect git commands
type: snippet
language: git
tags: [configuration]
author: chalarangelo
cover: purple-flower-bunch
dateModified: 2021-04-13T21:10:59+03:00
---
Configures git to autocorrect mistyped commands.
- Use `git config --global help.autocorrect 1` to enable git's autocorrect.
```shell
git config --global help.autocorrect 1
```
```shell
git config --global help.autocorrect 1
git sttaus # Runs `git status` instead
```

View File

@ -0,0 +1,34 @@
---
title: Automatically find the commit that introduced a bug
type: snippet
language: git
tags: [commit,branch]
author: chalarangelo
cover: pink-flower-tree
dateModified: 2021-04-13T21:10:59+03:00
---
Uses a binary search algorithm and a given script to find which commit in history introduced a bug.
- Use `git bisect start` to start the process.
- Use `git bisect good <commit>` to mark a `<commit>` as "good", indicating it is known to be bug-free.
- Use `git bisect bad <commit>` to mark a different `<commit>` as "bad" indicating it has the bug.
- Use `git bisect run <command>` to run the given `<command>` 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 `<commit>` to reset to.
```shell
git bisect start
git bisect good <commit>
git bisect bad <commit>
git bisect run <command>
git bisect reset [<commit>]
```
```shell
git bisect start
git bisect good 3050fc0de
git bisect bad c191f90c7
git bisect run npm test # Run `npm test` for each commit
# ... some time later the bad commit will be printed
git bisect reset # Goes to the original branch
```

View File

@ -0,0 +1,23 @@
---
title: Automate upstream branch creation
type: snippet
language: git
tags: [configuration,repository]
author: chalarangelo
cover: violin
dateModified: 2022-10-19T05:00:00-04:00
---
Configures the repository to automatically create upstream branches on push.
- Use `git config --add --bool` to enable automatic upstream branch creation on push.
- You can use the `--global` flag to enable this setting globally.
```shell
git config [--global] --add --bool
```
```shell
git config --global --add --bool
# `git push` will automatically create new branches, if they don't exist
```

View File

@ -0,0 +1,22 @@
---
title: Find branches containing a commit
type: snippet
language: git
tags: [branch,commit]
cover: dark-leaves
dateModified: 2021-04-13T21:10:59+03:00
---
Prints all the branches containing a specific commit.
- Use `git branch --contains <commit>` to see a list of all branches containing `<commit>`.
```shell
git branch --contains <commit>
```
```shell
git branch --contains 3050fc0d3
# patch-1
# patch-2
```

View File

@ -0,0 +1,22 @@
---
title: Find branches not containing a commit
type: snippet
language: git
tags: [branch,commit]
cover: blue-sunrise
dateModified: 2021-04-13T21:10:59+03:00
---
Prints all the branches not containing a specific commit.
- Use `git branch --no-contains <commit>` to see a list of all branches not containing `<commit>`.
```shell
git branch --no-contains <commit>
```
```shell
git branch --no-contains 3050fc0d3
# patch-3
# patch-4
```

View File

@ -0,0 +1,22 @@
---
title: Change the remote URL
type: snippet
language: git
tags: [repository]
author: chalarangelo
cover: rocky-lake
dateModified: 2021-04-13T21:10:59+03:00
---
Changes the URL of the remote repository.
- Use `git remote set-url origin <url>` to change the URL of the remote repository to `<url>`.
```shell
git remote set-url origin <url>
```
```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"
```

View File

@ -0,0 +1,22 @@
---
title: Clone missing submodules
type: snippet
language: git
tags: [repository,submodule]
author: chalarangelo
cover: forest-balcony
dateModified: 2021-04-13T21:10:59+03:00
---
Clones missing submodules and checks out commits.
- Use `git submodule update --init --recursive` to clone missing submodules and checkout commits.
```shell
git submodule update --init --recursive
```
```shell
git submodule update --init --recursive
# Clones missing submodules and checks out commits
```

View File

@ -0,0 +1,27 @@
---
title: Clone a repository
type: snippet
language: git
tags: [repository,remote]
cover: fruit-feast
dateModified: 2021-04-13T21:10:59+03:00
---
Clones an existing repository, creating a local copy of it.
- Use `git clone <url>` to clone an existing repository from `<url>` to a local directory. The directory's name will be based on the name of the cloned repository.
- Alternatively, use `git clone <url> [<directory>]` to clone the repository into the specified local `<directory>`.
```shell
git clone <url> [<directory>]
```
```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
git clone https://github.com/30-seconds/30-seconds-of-code.git my-project
# Clones the repository in a new directory named 'my-project'
cd my-project
```

View File

@ -0,0 +1,25 @@
---
title: Change the last commit's author
type: snippet
language: git
tags: [commit]
author: chalarangelo
cover: symmetry-cloudy-mountain
dateModified: 2022-05-03T05:00:00-04:00
---
Updates the last commit's author without changing its contents.
- Use `git commit --amend` to edit the last commit.
- Use the `--author` option to change the `<name>` and `<email>` of the commit's author.
```shell
git commit --amend --author="<name> <email>"
```
```shell
# Make some changes to files
git add .
git commit --amend --author="Duck Quackers <cool.duck@qua.ck>"
# The last commit's author is now `Duck Quackers`
```

View File

@ -0,0 +1,24 @@
---
title: Create a commit by a different author
type: snippet
language: git
tags: [commit]
cover: new-plant
dateModified: 2021-04-13T21:10:59+03:00
---
Creates a new commit by the specified author.
- Use `git commit -m <message>` to create a new commit with the specified `<message>`.
- Use the `--author` option to change the `<name>` and `<email>` of the commit's author.
```shell
git commit -m <message> --author="<name> <email>"
```
```shell
# Make some changes to files
git add .
git commit -m "Fix the network bug" --author="Duck Quackers <cool.duck@qua.ck>"
# Creates a commit by `Duck Quackers`
```

View File

@ -0,0 +1,22 @@
---
title: Add a commit message template
type: snippet
language: git
tags: [repository,configuration]
author: chalarangelo
cover: river-house-lights
dateModified: 2021-04-13T21:10:59+03:00
---
Sets up a commit message template for the current repository.
- Use `git config commit.template <file>` to specify `<file>` as the commit message template for the current repository.
```shell
git config commit.template <file>
```
```shell
git config commit.template "commit-template"
# Sets "commit-template" as the commit message template
```

View File

@ -0,0 +1,23 @@
---
title: Commit without running git hooks
type: snippet
language: git
tags: [commit]
cover: fishermen
dateModified: 2021-04-13T21:10:59+03:00
---
Creates a new commit skipping the pre-commit and commit-msg hooks.
- Use `git commit --no-verify -m <message>` to commit staged changes without running git hooks.
```shell
git commit --no-verify -m <message>
```
```shell
# Make some changes to files, ones that your precommit hook might not allow
git add .
git commit --no-verify -m "Unsafe commit"
# Creates a commit with the message "Unsafe commit", without running git hooks
```

View File

@ -0,0 +1,29 @@
---
title: Configure git user information
type: snippet
language: git
tags: [configuration,repository]
cover: pineapple-at-work
dateModified: 2021-04-13T21:10:59+03:00
---
Configures user information for git.
- Use `git config user.email <email>` to set the user's email for the current repository.
- Use `git config user.name <name>` to set the user's name for the current repository.
- You can use the `--global` flag to configure global user information.
```shell
git config [--global] user.email <email>
git config [--global] user.name <name>
```
```shell
git config user.email "cool.duck@qua.ck"
git config user.name "Duck Quackers"
# Configures user for current repository
git config --global user.email "cool.duck@qua.ck"
git config --global user.name "Duck Quackers"
# Configures global git user
```

View File

@ -0,0 +1,23 @@
---
title: Copy a file from another branch
type: snippet
language: git
tags: [branch]
author: chalarangelo
cover: sea-view-2
dateModified: 2021-04-13T21:10:59+03:00
---
Copies a file from another branch to the current branch.
- Use `git checkout <branch> <file>` to copy the specified `<file>` from the specified `<branch>`.
```shell
git checkout <branch> <file>
```
```shell
git checkout patch-2
git checkout patch-1 "30seconds.txt"
# `patch-2` branch now contains the 30seconds.txt file from `patch-1`
```

View File

@ -0,0 +1,26 @@
---
title: Create a new branch
type: snippet
language: git
tags: [branch,remote]
cover: flower-pond
dateModified: 2021-04-13T21:10:59+03:00
---
Creates and switches to a new branch, optionally setting up a remote tracking branch.
- Use `git checkout -b <branch>` to create a new branch with the specified name and switch to it.
- You can optionally add `-t <remote>/<branch>` to set up a remote tracking branch for the newly created branch.
- Note: You can alternatively use `git branch <branch> [-t <remote>/<branch>]` and then `git checkout <branch>` separately.
```shell
git checkout -b <branch> [-t <remote>/<branch>]
```
```shell
git checkout -b patch-1
# Local branch, without a remote tracking branch
git checkout -b patch-2 -t origin/patch-2
# Local branch and remote tracking branch with the same name
```

View File

@ -0,0 +1,23 @@
---
title: Create a commit
type: snippet
language: git
tags: [commit]
cover: baloons-field
dateModified: 2021-04-13T21:10:59+03:00
---
Creates a new commit containing the staged changes.
- Use `git commit -m <message>` to create a new commit with the specified `<message>`.
```shell
git commit -m <message>
```
```shell
# Make some changes to files
git add .
git commit -m "Fix the network bug"
# Creates a commit with the message "Fix the network bug"
```

View File

@ -0,0 +1,21 @@
---
title: Create an empty commit
type: snippet
language: git
tags: [commit]
cover: colorful-plastic
dateModified: 2021-04-13T21:10:59+03:00
---
Creates an empty commit.
- Use `git commit --allow-empty -m <message>` to create an empty commit with the provided `<message>`.
```shell
git commit --allow-empty -m <message>
```
```shell
git commit --allow-empty -m "Empty commit"
# Creates an empty commit with the message "Empty commit"
```

View File

@ -0,0 +1,26 @@
---
title: Create a fixup commit
type: snippet
language: git
tags: [commit]
author: chalarangelo
cover: tools
dateModified: 2021-04-13T21:10:59+03:00
---
Creates a fixup commit that can be autosquashed in the next rebase.
- Use `git commit --fixup <commit>` to create a fixup commit for the specified `<commit>`.
- After running `git rebase --autosquash`, fixup commits will be automatically squashed into the commits they reference.
```shell
git commit --fixup <commit>
```
```shell
git add .
git commit --fixup 3050fc0de
# Created a fixup commit for `3050fc0de`
git rebase HEAD~5 --autosquash
# Now the fixup commit has been squashed
```

View File

@ -0,0 +1,27 @@
---
title: Create a new repository
type: snippet
language: git
tags: [repository]
cover: violin
dateModified: 2021-04-13T21:10:59+03:00
---
Initializes a new git repository, setting up all the configuration files needed by git.
- Use `git init` to initialize an empty repository in the current directory.
- Alternatively, use `git init [<directory>]` to initialize the repository in the specified `<directory>`.
- Note: Running `git init` in an existing repository is safe.
- Note: You only need to run `git init` once per repository.
```shell
git init [<directory>]
```
```shell
cd ~/my_project
git init # Initializes a repo in ~/my_project
cd ~
git init my_project # Initializes a repo in ~/my_project
```

View File

@ -0,0 +1,21 @@
---
title: Get the current branch name
type: snippet
language: git
tags: [branch]
cover: cherry-trees
dateModified: 2021-04-13T21:10:59+03:00
---
Prints the current branch name.
- Use `git rev-parse --abbrev-ref HEAD` to print the name of the current branch.
```shell
git rev-parse --abbrev-ref HEAD
```
```shell
git checkout patch-1
git rev-parse --abbrev-ref HEAD # Prints `patch-1`
```

View File

@ -0,0 +1,21 @@
---
title: Delete a branch
type: snippet
language: git
tags: [repository,branch]
cover: volcano-sunset
dateModified: 2021-04-13T21:10:59+03:00
---
Deletes a local branch.
- Use `git branch -d <branch>` to delete the specified local `<branch>`.
```shell
git branch -d <branch>
```
```shell
git checkout master
git branch -d patch-1 # Deletes the `patch-1` local branch
```

View File

@ -0,0 +1,32 @@
---
title: Delete detached branches
type: snippet
language: git
tags: [repository,branch]
cover: brown-bird
dateModified: 2021-04-13T21:10:59+03:00
---
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.
```shell
git fetch --all --prune
```
```shell
git checkout master
git branch
# master
# patch-1
# patch-2
# Assuming `patch-1` is detached
git fetch --all --prune
git branch
# master
# patch-2
```

View File

@ -0,0 +1,33 @@
---
title: Delete merged branches
type: snippet
language: git
tags: [repository,branch]
cover: duck-plants
dateModified: 2021-04-13T21:10:59+03:00
---
Deletes all local merged branches.
- Use `git branch --merged <branch>` to list all branches merged into `<branch>`.
- Use the pipe operator (`|`) to pipe the output and `grep -v "(^\*|<branch>)"` to exclude the current and the target `<branch>`.
- Use the pipe operator (`|`) to pipe the output and `xargs git branch -d` to delete all of the found branches.
```shell
git branch --merged <branch> | grep -v "(^\*|<branch>)" | xargs git branch -d
```
```shell
git checkout master
git branch
# master
# patch-1
# patch-2
# Assuming `patch-1` is merged into master
git branch --merged master | grep -v "(^\*|master)" | xargs git branch -d
git branch
# master
# patch-2
```

View File

@ -0,0 +1,21 @@
---
title: Delete a remote branch
type: snippet
language: git
tags: [repository,branch]
cover: waves-from-above
dateModified: 2021-04-13T21:10:59+03:00
---
Deletes a remote branch.
- Use `git push -d <remote> <branch>` to delete the specified remote `<branch>` on the given `<remote>`.
```shell
git push -d <remote> <branch>
```
```shell
git checkout master
git push -d origin patch-1 # Deletes the `patch-1` remote branch
```

View File

@ -0,0 +1,21 @@
---
title: Delete a stash
type: snippet
language: git
tags: [repository,stash]
author: chalarangelo
cover: budapest-palace
dateModified: 2021-04-13T21:10:59+03:00
---
Deletes a specific stash.
- Use `git stash drop <stash>` to delete the given `<stash>`.
```shell
git stash drop <stash>
```
```shell
git stash drop stash@{1} # Deletes `stash@{1}`
```

View File

@ -0,0 +1,22 @@
---
title: Delete all stashes
type: snippet
language: git
tags: [repository,stash]
author: chalarangelo
cover: little-tree
dateModified: 2021-04-13T21:10:59+03:00
---
Deletes all stashes.
- Use `git stash clear` to delete all stashes.
```shell
git stash clear
```
```shell
git stash clear
# Deletes all stashes
```

View File

@ -0,0 +1,28 @@
---
title: Delete a submodule
type: snippet
language: git
tags: [repository,submodule]
author: chalarangelo
cover: silver-flat-screen
dateModified: 2021-04-13T21:10:59+03:00
---
Deletes a submodule from the repository.
- Use `git submodule deinit -f -- <submodule>` to unregister the specified `<submodule>`.
- Use `rm -rf .git/modules/<submodule>` to remove the directory of the submodule.
- Use `git rm -f <submodule>` to remove the working tree of the submodule.
```shell
git submodule deinit -f -- <submodule>
rm -rf .git/modules/<submodule>
git rm -f <submodule>
```
```shell
git submodule deinit -f -- 30code
rm -rf .git/modules/30code
git rm -f 30code
# Removes the `30code` submodule
```

View File

@ -0,0 +1,22 @@
---
title: View difference between two branches
type: snippet
language: git
tags: [branch]
author: chalarangelo
cover: two-doors
dateModified: 2021-04-13T21:10:59+03:00
---
Displays the difference between two branches.
- Use `git diff <branch>..<other-branch> ` to view the difference between `<branch>` and `<other-branch>`.
```shell
git diff <branch>..<other-branch>
```
```shell
git diff patch-1..patch-2
# Displays the difference between branches `patch-1` and `patch-2`
```

View File

@ -0,0 +1,26 @@
---
title: Disable fast forward merging by default
type: snippet
language: git
tags: [configuration,repository]
author: chalarangelo
cover: people-on-beach
dateModified: 2021-07-03T05:00:00-04:00
---
Disables the default fast forwarding on merge commits.
- Use `git config --add merge.ff false` to disable fast-forward merging for all branches, even if it is possible.
- You can use the `--global` flag to configure this option globally.
```shell
git config [--global] --add merge.ff false
```
```shell
git config --global --add merge.ff false
git checkout master
git merge my-branch
# Will never fast forward even if it's possible
```

View File

@ -0,0 +1,21 @@
---
title: Discard uncommitted changes
type: snippet
language: git
tags: [branch]
cover: arrays
dateModified: 2021-04-13T21:10:59+03:00
---
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.
```shell
git reset --hard HEAD
```
```shell
git reset --hard HEAD
# Discards all unstaged changes
```

View File

@ -0,0 +1,21 @@
---
title: Discard untracked changes
type: snippet
language: git
tags: [branch]
cover: cold-mountains
dateModified: 2021-04-13T21:10:59+03:00
---
Discards all untracked changes to the current branch.
- Use `git clean -f -d` to discard all untracked changes to the current branch.
```shell
git clean -f -d
```
```shell
git clean -f -d
# Discards all untracked changes
```

View File

@ -0,0 +1,21 @@
---
title: Edit git configuration file
type: snippet
language: git
tags: [configuration]
cover: terminal
dateModified: 2021-04-13T21:10:59+03:00
---
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.
```shell
git config --global -e
```
```shell
git config --global -e
# Opens the git configuration file in the default git text editor
```

View File

@ -0,0 +1,20 @@
---
title: Fetch latest changes from remote
type: snippet
language: git
tags: [repository]
cover: playing-fetch
dateModified: 2021-04-13T21:10:59+03:00
---
Fetches the latest changes from the remote.
- Use `git fetch` to get the latest changes from the remote, without applying them.
```shell
git fetch
```
```shell
git fetch # Fetches the latest updates from the remote
```

View File

@ -0,0 +1,25 @@
---
title: Find lost files
type: snippet
language: git
tags: [repository]
author: chalarangelo
cover: hard-disk
dateModified: 2021-04-13T21:10:59+03:00
---
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.
```shell
git fsck --lost-found
```
```shell
git fsck --lost-found
# dangling commit 3050fc0de
# dangling blob 807e3fa41
# dangling commit 59ff8481d
```

View File

@ -0,0 +1,28 @@
---
title: Update remote branch after rewriting history
type: snippet
language: git
tags: [branch]
author: chalarangelo
cover: compass
dateModified: 2021-04-13T21:10:59+03:00
---
Forces an update of the remote branch after 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.
```shell
git push -f
```
```shell
git checkout patch-1
git pull
git rebase master
# Local `patch-1` branch has been rebased onto `master`, thus diverging
# from the remote `patch-1` branch
git push -f # Force update the remote `patch-1` branch
```

View File

@ -0,0 +1,29 @@
---
title: Perform an interactive rebase
type: snippet
language: git
tags: [branch]
author: chalarangelo
cover: tea-laptop-table
dateModified: 2021-04-13T21:10:59+03:00
---
Performs an interactive rebase.
- Use `git rebase -i <commit>` to perform an interactive rebase.
- You can edit the rebase file to change the order of the commits and the action to perform for each one (pick, squash, drop, reword etc.).
- 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`.
```shell
git rebase -i [--autosquash] <commit>
```
```shell
git rebase -i 3050fc0de
# Performs an interactive rebase starting from `3050fc0de`
git rebase -i --autosquash HEAD~5
# Performs an interactive rebase of the last 5 commits,
# automatically squashing fixup commits
```

View File

@ -0,0 +1,22 @@
---
title: Configure line endings
type: snippet
language: git
tags: [repository,configuration]
author: chalarangelo
cover: leaves-read
dateModified: 2021-04-13T21:10:59+03:00
---
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`).
```shell
git config core.eol [lf | crlf]
```
```shell
git config core.eol lf # Configured to use UNIX line endings
```

View File

@ -0,0 +1,25 @@
---
title: List all git aliases
type: snippet
language: git
tags: [configuration]
cover: book-chair
dateModified: 2021-04-13T21:10:59+03:00
---
Prints a list of all git aliases.
- Use `git config -l` to list all variables set in the configuration file.
- 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.
```shell
git config -l | grep alias | sed 's/^alias\.//g'
```
```shell
git config -l | grep alias | sed 's/^alias\.//g'
# st=status
# co=checkout
# rb=rebase
```

View File

@ -0,0 +1,22 @@
---
title: Lists all stashes
type: snippet
language: git
tags: [repository,stash]
author: chalarangelo
cover: golden-gate-bridge
dateModified: 2021-04-13T21:10:59+03:00
---
Displays a list of all stashes.
- Use `git stash list` to view a list of all stashes.
```shell
git stash list
```
```shell
git stash list
# stash@{0}: WIP on patch-1: ee52eda Fix network bug
```

View File

@ -0,0 +1,35 @@
---
title: Manually find the commit that introduced a bug
type: snippet
language: git
tags: [commit,branch]
author: chalarangelo
cover: blue-computer
dateModified: 2021-04-13T21:10:59+03:00
---
Uses a binary search algorithm to manually find which commit in history introduced a bug.
- Use `git bisect start` to start the process.
- Use `git bisect good <commit>` to mark a `<commit>` as "good", indicating it is known to be bug-free.
- Use `git bisect bad <commit>` to mark a different `<commit>` as "bad" indicating it has the bug.
- 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 `<commit>` to reset to.
```shell
git bisect start
git bisect good <commit>
git bisect bad <commit>
git bisect (bad | good)
git bisect reset [<commit>]
```
```shell
git bisect start
git bisect good 3050fc0de
git bisect bad c191f90c7
git bisect good # Current commit is good
git bisect bad # Current commit is buggy
# ... some time later the bad commit will be printed
git bisect reset # Goes to the original branch
```

View File

@ -0,0 +1,25 @@
---
title: Merge a branch and create a merge commit
type: snippet
language: git
tags: [repository,branch]
cover: meteora
dateModified: 2021-04-13T21:10:59+03:00
---
Merges a branch into the current branch, creating a merge commit.
- Use `git checkout <target-branch>` to switch to the branch into which you want to merge.
- Use `git merge --no-ff -m <message> <source-branch>` to merge a branch into the current branch, creating a merge commit with the specified `<message>`.
```shell
git checkout <target-branch>
git merge --no-ff -m <message> <source-branch>
```
```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
# with the message "Merge patch-1"
```

View File

@ -0,0 +1,23 @@
---
title: Merge a branch
type: snippet
language: git
tags: [repository,branch]
cover: sparkles
dateModified: 2021-04-13T21:10:59+03:00
---
Merges a branch into the current branch.
- Use `git checkout <target-branch>` to switch to the branch into which you want to merge.
- Use `git merge <source-branch>` to merge a branch into the current branch.
```shell
git checkout <target-branch>
git merge <source-branch>
```
```shell
git checkout master
git merge patch-1 # Merges the `patch-1` branch into `master`
```

View File

@ -0,0 +1,32 @@
---
title: Move commits from master to a new branch
type: snippet
language: git
tags: [branch,repository]
author: chalarangelo
cover: red-succulent
dateModified: 2021-04-13T21:10:59+03:00
---
Moves local commits from the `master` branch to a new branch.
- Use `git branch <branch>` to create a new branch at the tip of the current `master`.
- Use `git reset HEAD~<n> --hard` to rewind back `<n>` commits and discard changes.
- Use `git checkout <branch>` to switch to the new branch.
- Only works if the changes have only been committed locally and not pushed to the remote.
```shell
git branch <branch>
git reset HEAD~<n> --hard
git checkout <branch>
```
```shell
git checkout master
git add .
git commit -m "Fix network bug"
git branch patch-1
# `patch-1` branch is created containing the commit "Fix network bug"
git reset HEAD~1 --hard # Remove the commit from `master`
git checkout patch-1
```

View File

@ -0,0 +1,21 @@
---
title: Optimize the local repository
type: snippet
language: git
tags: [repository]
author: chalarangelo
cover: automaton
dateModified: 2021-04-13T21:10:59+03:00
---
Optimizes the local repository.
- Use `git gc --prune=now --aggressive` to garbage collect loose objects.
```shell
git gc --prune=now --aggressive
```
```shell
git gc --prune=now --aggressive # Optimizes the local repository
```

View File

@ -0,0 +1,29 @@
---
title: Pick changes from one or more commits
type: snippet
language: git
tags: [commit,branch]
author: chalarangelo
cover: sunflowers
dateModified: 2021-04-13T21:10:59+03:00
---
Applies the changes introduced by one or more commits.
- Use `git cherry-pick <commit>` to pick changes from a single commit.
- Use `git cherry-pick <commit-1> <commit-2>...` to pick changes from all space-separated commits.
- Use `git cherry-pick <first-commit>..<last-commit>` to pick changes from a range of commits.
```shell
git cherry-pick (<commit>... | <first-commit>..<last-commit>)
```
```shell
git cherry-pick 3050fc0de # Picks changes from the commit `3050fc0de`
git cherry-pick 3050fc0de c191f90c7
# Picks changes from the commits `3050fc0de`, `c191f90c7` and `0b552a6d4`
git cherry-pick 3050fc0de..c191f90c7
# Picks changes from the commits in the range `3050fc0de` - `c191f90c7`
```

View File

@ -0,0 +1,22 @@
---
title: Pull all submodules from remote
type: snippet
language: git
tags: [repository,submodule]
author: chalarangelo
cover: workspace-with-speaker
dateModified: 2021-04-13T21:10:59+03:00
---
Pulls all submodules from their respective remotes.
- Use `git submodule update --recursive --remote` to pull all submodules from their respective remotes.
```shell
git submodule update --recursive --remote
```
```shell
git submodule update --recursive --remote
# Pulls all submodules from their respective remotes
```

View File

@ -0,0 +1,22 @@
---
title: Pull latest changes from remote
type: snippet
language: git
tags: [repository,branch]
cover: last-light
dateModified: 2021-04-13T21:10:59+03:00
---
Pulls the latest changes from the remote tracking branch.
- Use `git pull` to fetch and apply the latest changes from the remote.
```shell
git pull
```
```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
```

View File

@ -0,0 +1,32 @@
---
title: Purge a file from history
type: snippet
language: git
tags: [repository,remote]
author: chalarangelo
cover: white-flower
dateModified: 2021-04-13T21:10:59+03:00
---
Completely purges a file from history.
- Use `git rm --cached --ignore-unmatch <path>` to delete the file in the specified `<path>`.
- Use `git filter-branch --force --index-filter <command> --prune-empty --tag-name-filter cat -- --all` to rewrite the branch's history, passing it the previous command.
- You can optionally use `git push <remote> --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.
```shell
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch <path>" \
--prune-empty --tag-name-filter cat -- --all
git push <remote> --force --all
```
```shell
git filter-branch --force --index-filter \
"git rm --cached --ignore-unmatch config/apiKeys.json" \
--prune-empty --tag-name-filter cat -- --all
# Purges `config/apiKeys.json` from history
git push origin --force --all
# Force pushes the changes to the remote repository
```

View File

@ -0,0 +1,22 @@
---
title: Push local changes to remote
type: snippet
language: git
tags: [repository,branch]
cover: dark-cloud
dateModified: 2021-04-13T21:10:59+03:00
---
Pushes the current branch's changes to the remote.
- Use `git push` to push the latest changes from the local branch to the remote.
```shell
git push
```
```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
```

View File

@ -0,0 +1,29 @@
---
title: Rebase onto another branch
type: snippet
language: git
tags: [branch]
cover: sliced-fruits
dateModified: 2021-04-13T21:10:59+03:00
---
Rebases the current branch onto another branch.
- Use `git checkout <branch>` to switch to the `<branch>` to be rebased.
- Use `git rebase <base-branch>` to rebase the current branch onto `<base-branch>`.
```shell
git checkout <branch>
git rebase <base-branch>
```
```shell
git checkout patch-1
git rebase master
# `patch-1` is rebased onto `master`
git checkout patch-2
git fetch origin # Fetch latest remote branches
git rebase origin/master
# `patch-2` is rebased onto the latest remote `master`
```

View File

@ -0,0 +1,24 @@
---
title: Remove a file from the last commit
type: snippet
language: git
tags: [commit]
cover: cancel-typographer
dateModified: 2021-04-13T21:10:59+03:00
---
Removes a file from the last commit without changing its message.
- Use `git rm —-cached <file>` to remove the specified `<file>` from the index.
- Use `git commit —-amend` to update the contents of the last commit, without changing its message.
```shell
git rm —-cached <file>
git commit —-amend
```
```shell
git rm —-cached "30-seconds.txt"
git commit —-amend
# Removes `30-seconds.txt` from the last commit
```

View File

@ -0,0 +1,22 @@
---
title: Rename a branch
type: snippet
language: git
tags: [branch]
cover: bug
dateModified: 2021-04-13T21:10:59+03:00
---
Renames a local branch.
- Use `git branch -m <old-name> <new-name>` to rename `<old-name>` to `<new-name>`.
```shell
git branch -m <old-name> <new-name>
```
```shell
git checkout master
git branch -m patch-1 patch-2
# Renames `patch-1` to `patch-2`
```

View File

@ -0,0 +1,30 @@
---
title: Rename remote branch
type: snippet
language: git
tags: [branch]
cover: horse-sunset
dateModified: 2021-04-13T21:10:59+03:00
---
Renames a branch both locally and on the remote.
- Use `git branch -m <old-name> <new-name>` to rename the local `<old-name>` branch to `<new-name>`.
- Use `git push origin --delete <old-name>` to delete the old remote branch.
- Use `git checkout <new-name>` to switch to the renamed branch.
- Use `git push origin -u <new-name>` to set `<new-name>` as the remote branch for the renamed branch.
```shell
git branch -m <old-name> <new-name>
git push origin --delete <old-name>
git checkout <new-name>
git push origin -u <new-name>
```
```shell
git checkout master
git branch -m patch-1 patch-2 # Renamed the local branch to `patch-2`
git push origin --delete patch-1
git checkout patch-2
git push origin -u patch-2 # Renames the remote branch to `patch-2`
```

View File

@ -0,0 +1,27 @@
---
title: Reset master to match remote
type: snippet
language: git
tags: [repository,branch]
cover: old-consoles
dateModified: 2021-04-13T21:10:59+03:00
---
Resets the local `master` branch to match the one on the remote.
- Use `git fetch origin` to retrieve the latest updates from 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.
```shell
git fetch origin
git checkout master
git reset --hard origin/master
```
```shell
git fetch origin
git checkout master
git reset --hard origin/master
# Local `master` branch is now up to date with remote `master`
```

View File

@ -0,0 +1,23 @@
---
title: Restore a deleted file
type: snippet
language: git
tags: [branch]
author: chalarangelo
cover: succulent-red-light
dateModified: 2021-04-13T21:10:59+03:00
---
Restores a file deleted in a specific commit.
- Use `git checkout <commit>^ -- <file>` to restore the specified `<file>` deleted in the specified `<commit>`.
```shell
git checkout <commit>^ -- <file>
```
```shell
# "30seconds.txt" was deleted in the commit `3050fc0de`
git checkout 3050fc0de^ -- "30seconds.txt"
# Restores the 30seconds.txt file
```

View File

@ -0,0 +1,26 @@
---
title: Rewind back n commits
type: snippet
language: git
tags: [branch,commit]
cover: lake-trees
dateModified: 2021-04-13T21:10:59+03:00
---
Rewinds the current branch by a given number of commits.
- Use `git reset HEAD~<n>` to rewind the current branch `<n>` 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.
```shell
git reset [--hard] HEAD~<n>
```
```shell
git reset HEAD~5
# Rewinds back 5 commits but keeps changes in the working directory
git reset --hard HEAD~3
# Rewinds back 3 commits and deletes changes
```

View File

@ -0,0 +1,26 @@
---
title: Rewind back to a specific commit
type: snippet
language: git
tags: [branch,commit]
cover: walking
dateModified: 2021-04-13T21:10:59+03:00
---
Rewinds the current branch by a given number of commits.
- Use `git reset <commit>` to rewind the current branch to the specified `<commit>`.
- 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.
```shell
git reset [--hard] <commit>
```
```shell
git reset 3050fc0d3
# Rewinds back to `3050fc0d3` but keeps changes in the working directory
git reset --hard c0d30f305
# Rewinds back to `c0d30f305` and deletes changes
```

View File

@ -0,0 +1,30 @@
---
title: Create a stash
type: snippet
language: git
tags: [repository,stash]
author: chalarangelo
cover: purple-leaves
dateModified: 2021-04-13T21:10:59+03:00
---
Saves the current state of the working directory and index into a new stash.
- Use `git stash save` to save 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 `<message>` for the stash.
```shell
git stash save [-u] [<message>]
```
```shell
git stash save
# Creates a new stash
git stash save -u
# Creates a new stash, including untracked files
git stash save "Bugfix WIP"
# Creates a new stash with the message "Bugfix WIP"
```

View File

@ -0,0 +1,26 @@
---
title: Set default push branch name
type: snippet
language: git
tags: [configuration,branch]
author: chalarangelo
cover: pink-flower
dateModified: 2021-06-30T05:00:00-04:00
---
Use the name of the current branch when pushing by default as the name of the remote branch.
- Use `git config push.default current` to set the name of the remote branch to the one of the current local branch as the default.
- You can use the `--global` flag to configure this option globally.
```shell
git config [--global] push.default current
```
```shell
git config --global push.default current
git checkout -b my-branch
git push -u
# Pushes to origin/my-branch
```

View File

@ -0,0 +1,21 @@
---
title: Configure the git text editor
type: snippet
language: git
tags: [configuration]
cover: purple-sunset-beach
dateModified: 2021-04-13T21:10:59+03:00
---
Configures the text editor used by git.
- Use `git config --global core.editor <editor-command>` to call `<editor-command>` as the git text editor.
```shell
git config --global core.editor <editor-command>
```
```shell
git config --global core.editor "code --wait"
# Sets VS Code as the git text editor
```

View File

@ -0,0 +1,25 @@
---
title: View branches sorted by date
type: snippet
language: git
tags: [repository,branch]
author: chalarangelo
cover: sea-view
dateModified: 2021-04-13T21:10:59+03:00
---
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 <kbd>Q</kbd> to exit.
```shell
git branch --sort=-committerdate
```
```shell
git branch --sort=-committerdate
# master
# patch-1
# patch-2
```

View File

@ -0,0 +1,28 @@
---
title: Add files to the staging area
type: snippet
language: git
tags: [commit]
cover: round-leaves
dateModified: 2021-04-13T21:10:59+03:00
---
Adds files to the staging area.
- Use `git add <pathspec>` to add files to the staging area.
- `<pathspec>` can be a filename or a fileglob.
```shell
git add <pathspec>
```
```shell
git add "30seconds.txt"
# Add the file `30seconds.txt` to the staging area
git add src/*.json
# Add all files with a `.json` extension in the `src` directory
git add .
# Adds all changes to the staging area
```

View File

@ -0,0 +1,21 @@
---
title: Switch to a branch
type: snippet
language: git
tags: [branch]
cover: bridge
dateModified: 2021-04-13T21:10:59+03:00
---
Switches to an existing branch.
- Use `git checkout <branch>` to switch to the specified branch.
- Note: In newer versions of git, you can also use `git switch <branch>`.
```shell
git checkout <branch>
```
```shell
git checkout patch-1 # Switches to the branch named `patch-1`
```

View File

@ -0,0 +1,22 @@
---
title: Return to previous branch
type: snippet
language: git
tags: [branch]
cover: beach-riders
dateModified: 2021-04-13T21:10:59+03:00
---
Switches back to the last branch.
- Use `git checkout -` to switch back to the previous branch.
```shell
git checkout -
```
```shell
git checkout patch-1
git checkout master
git checkout - # Switches to `patch-1`
```

View File

@ -0,0 +1,21 @@
---
title: Undo a commit
type: snippet
language: git
tags: [commit,branch]
cover: mask-quiet
dateModified: 2021-04-13T21:10:59+03:00
---
Undoes a specified commit without rewriting history.
- Use `git revert <commit>` to revert the specified `<commit>`, creating a new commit with the inverse of the commit's changes.
```shell
git revert <commit>
```
```shell
git revert 3050fc0d3
# Reverts the commit `3050fc0d3`
```

View File

@ -0,0 +1,21 @@
---
title: Undo the last commit
type: snippet
language: git
tags: [commit,branch]
cover: racoon
dateModified: 2021-04-13T21:10:59+03:00
---
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.
```shell
git revert HEAD
```
```shell
git revert HEAD
# Reverts the last commit
```

View File

@ -0,0 +1,29 @@
---
title: Remove files from the staging area
type: snippet
language: git
tags: [commit]
author: chalarangelo
cover: coconuts
dateModified: 2021-04-13T21:10:59+03:00
---
Removes files from the staging area.
- Use `git restore --staged <pathspec>` to remove files from the staging area.
- `<pathspec>` can be a filename or a fileglob.
```shell
git restore --staged <pathspec>
```
```shell
git restore --staged "30seconds.txt"
# Remove the file `30seconds.txt` from the staging area
git restore --staged src/*.json
# Remove all files with a `.json` extension in the `src` directory
git restore --staged .
# Remove all changes from the staging area
```

View File

@ -0,0 +1,25 @@
---
title: Edit the last commit
type: snippet
language: git
tags: [commit]
cover: tram-car
dateModified: 2021-04-13T21:10:59+03:00
---
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.
```shell
git commit --amend --no-edit
```
```shell
git add .
git commit -m "Fix the network bug"
# Edit or add files
git add .
git commit --amend --no-edit
# The last commit includes the edited/added files
```

View File

@ -0,0 +1,23 @@
---
title: Change the last commit's message
type: snippet
language: git
tags: [commit]
cover: greek-coffee
dateModified: 2021-04-13T21:10:59+03:00
---
Updates the last commit's message without changing its contents.
- Use `git commit --amend -m <message>` to replace the last commit's message with the new `<message>`.
```shell
git commit --amend -m <message>
```
```shell
git add .
git commit -m "Fix the newtork bug"
git commit --amend -m "Fix the network bug"
# The last commit's message is now "Fix the network bug"
```

View File

@ -0,0 +1,24 @@
---
title: View local branches
type: snippet
language: git
tags: [repository,branch]
cover: aerial-view-port
dateModified: 2021-04-13T21:10:59+03:00
---
Prints a list of all local branches.
- Use `git branch` to display a list of all local branches.
- Use arrow keys to navigate, press <kbd>Q</kbd> to exit.
```shell
git branch
```
```shell
git branch
# master
# patch-1
# patch-2
```

View File

@ -0,0 +1,25 @@
---
title: View a summary of changes between two commits
type: snippet
language: git
tags: [repository,branch]
author: chalarangelo
cover: taking-photos
dateModified: 2021-04-13T21:10:59+03:00
---
Prints a summary of changes between two given commits.
- Use `git shortlog <commit>..<other-commit>` to view a summary of changes between the two given commits.
- Use arrow keys to navigate, press <kbd>Q</kbd> to exit.
```shell
git shortlog <commit>..<other-commit>
```
```shell
git shortlog 3050fc0de..HEAD
# Duck Quacking (2):
# Fix network bug
# Update documentation
```

View File

@ -0,0 +1,23 @@
---
title: View a visual graph of the repository
type: snippet
language: git
tags: [repository]
cover: city-view
dateModified: 2021-04-13T21:10:59+03:00
---
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 <kbd>Q</kbd> to exit.
```shell
git log --pretty=oneline --graph --decorate --all
```
```shell
git log --pretty=oneline --graph --decorate --all
# * 3050fc0de Fix network bug
# * c191f90c7 Initial commit
```

View File

@ -0,0 +1,25 @@
---
title: View commits by author
type: snippet
language: git
tags: [repository,commit]
cover: comic-glasses
dateModified: 2021-04-13T21:10:59+03:00
---
Prints all commits by the specified author.
- Use `git log --author=<author>` to retrieve all commits by the specified `<author>`.
- Use arrow keys to navigate, press <kbd>Q</kbd> to exit.
```shell
git log --author=<author>
```
```shell
git log --author="Duck Quacking"
# commit c191f90c7766ee6d5f24e90b552a6d446f0d02e4
# Author: 30 seconds of code
# Date: Tue Apr 6 11:11:08 2021 +0300
# [...]
```

View File

@ -0,0 +1,25 @@
---
title: View commits that manipulated a specific string
type: snippet
language: git
tags: [commit]
cover: bunny-poster
dateModified: 2021-04-13T21:10:59+03:00
---
Prints a list of all commits that manipulated a given string.
- Use `git log -S<string>` to find all commits that manipulated the specified `<string>`.
- Use arrow keys to navigate, press <kbd>Q</kbd> to exit.
```shell
git log -S<string>
```
```shell
git log -S"30-seconds"
# commit c191f90c7766ee6d5f24e90b552a6d446f0d02e4
# Author: 30 seconds of code
# Date: Tue Apr 6 11:11:08 2021 +0300
# [...]
```

View File

@ -0,0 +1,32 @@
---
title: View commits in a specific date range
type: snippet
language: git
tags: [repository,commit]
cover: organizer
dateModified: 2021-04-13T21:10:59+03:00
---
Prints all commits in the specified date range.
- Use `git log --since=<date-from> --until=<date-to>` to view a log of all commits between `<date-from>` and `<date-to>`.
- You can use only `--since=<date-from>` to see all commits since a specific date or only `--until=<date-to>` to view all commits up to a specific date
- Use arrow keys to navigate, press <kbd>Q</kbd> to exit.
```shell
git log [--since=<date-from>] [--until=<date-to>]
```
```shell
git log --since='Apr 1 2021' --until='Apr 4 2021'
# commit c191f90c7766ee6d5f24e90b552a6d446f0d02e4
# Author: 30 seconds of code
# Date: Tue Apr 6 11:11:08 2021 +0300
# [...]
git log --since='2 weeks ago'
# commit c191f90c7766ee6d5f24e90b552a6d446f0d02e4
# Author: 30 seconds of code
# Date: Tue Apr 6 11:11:08 2021 +0300
# [...]
```

View File

@ -0,0 +1,22 @@
---
title: View a short summary of commits without merge commits
type: snippet
language: git
tags: [repository,commit]
cover: river-flow
dateModified: 2021-04-13T21:10:59+03:00
---
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.
```shell
git log --oneline --no-merges
```
```shell
git log --oneline --no-merges
# 3050fc0de Fix network bug
# c191f90c7 Initial commit
```

View File

@ -0,0 +1,23 @@
---
title: View a short summary of commits
type: snippet
language: git
tags: [repository,commit]
cover: highlands
dateModified: 2021-04-13T21:10:59+03:00
---
Prints a short summary of all commits.
- Use `git log --oneline` to list a short summary of all commits.
```shell
git log --oneline
```
```shell
git log --oneline
# d540ba1ab Merge network bug fix
# 3050fc0de Fix network bug
# c191f90c7 Initial commit
```

View File

@ -0,0 +1,26 @@
---
title: View differences in changes
type: snippet
language: git
tags: [commit,branch]
author: chalarangelo
cover: plant-candle
dateModified: 2021-04-13T21:10:59+03:00
---
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.
```shell
git diff [--staged]
```
```shell
git diff
# Displays the differences between unstaged changes and the last commit
git diff --staged
# Displays the differences between staged changes and the last commit
```

View File

@ -0,0 +1,25 @@
---
title: View last commit
type: snippet
language: git
tags: [commit]
cover: green-plant
dateModified: 2021-04-13T21:10:59+03:00
---
Prints the last commit.
- Use `git log -1` to view the last commit.
- Use arrow keys to navigate, press <kbd>Q</kbd> to exit.
```shell
git log -1
```
```shell
git log -1
# commit c191f90c7766ee6d5f24e90b552a6d446f0d02e4
# Author: 30 seconds of code
# Date: Tue Apr 6 11:11:08 2021 +0300
# [...]
```

View File

@ -0,0 +1,24 @@
---
title: View merged branches
type: snippet
language: git
tags: [repository,branch]
cover: cobbled-street
dateModified: 2021-04-13T21:10:59+03:00
---
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 <kbd>Q</kbd> to exit.
```shell
git branch -a --merged
```
```shell
git checkout master
git branch -a --merged
# patch-1
# patch-2
```

View File

@ -0,0 +1,22 @@
---
title: View the remote URL
type: snippet
language: git
tags: [repository]
author: chalarangelo
cover: red-mountain
dateModified: 2021-04-13T21:10:59+03:00
---
Displays the URL of the remote repository.
- Use `git config --get remote.origin.url` to view the URL of the remote repository.
```shell
git config --get remote.origin.url
```
```shell
git config --get remote.origin.url
# https://github.com/30-seconds/30-seconds-of-code
```

View File

@ -0,0 +1,34 @@
---
title: View current status
type: snippet
language: git
tags: [branch]
author: chalarangelo
cover: periscope
dateModified: 2021-04-13T21:10:59+03:00
---
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
```shell
git status [-sb]
```
```shell
git status
# On branch patch-1
# Your branch is up to date with 'origin/patch-1'.
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
# 30-seconds.txt
#
# nothing added to commit but untracked files present (use "git add" to track)
git status -sb
# ## patch-1...origin/patch-1
# ?? 30-seconds.txt
```

View File

@ -0,0 +1,30 @@
---
title: View "undo" history
type: snippet
language: git
tags: [repository,branch]
cover: rock-climbing
dateModified: 2021-04-13T21:10:59+03:00
---
View git's reference logs. This is especially useful for finding references that don't show up in commit history.
- Use `git reflog` to display the git reference log.
- View your "undo" history
Because sometimes git log doesn't cut it, especially for commands that don't show up in your commit history.
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.
```shell
git reflog
```
```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
# 3050fc0de HEAD@{2}: rebase -i (pick): Fix network bug
# 93df3f495 (origin/patch-2) HEAD@{3}: rebase -i (start): checkout origin/master
# 69beaeabb HEAD@{4}: rebase -i (finish): returning to refs/heads/patch-1
```

23
snippets/git/template.md Normal file
View File

@ -0,0 +1,23 @@
---
title: Snippet name
type: snippet
language: git
tags: [branch]
cover: image
dateModified: 2021-06-13T05:00:00-04:00
---
Explain briefly what the snippet does.
- Explain briefly how the snippet works.
- Use bullet points for your snippet's explanation.
- Try to explain everything briefly but clearly.
```shell
git command <variable> [--option]
```
```shell
git command some-branch --quiet
# Output of running command on `some-branch`
```