Merge 30-seconds-of-git

This commit is contained in:
Angelos Chalaris
2023-05-01 22:37:49 +03:00
93 changed files with 2707 additions and 0 deletions

104
git/.gitignore vendored Normal file
View File

@ -0,0 +1,104 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port

73
git/CODE_OF_CONDUCT.md Normal file
View File

@ -0,0 +1,73 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
education, socio-economic status, nationality, personal appearance, race,
religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [mst10041967@gmail.com]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org

42
git/CONTRIBUTING.md Normal file
View File

@ -0,0 +1,42 @@
# Contribution Guidelines
**30 seconds of code** is powered by the community, so feel free to contribute in any way you can to help us!
## How you can help
- Submit pull requests with new snippets (see guidelines below) or snippet updates (tags, descriptions, explanations, typos, examples, code improvements).
- Open issues for things you want to see added, modified, discuss ideas or help out with existing issues.
## Ground rules
Breaking any of these rules will result in your pull request being closed. Please follow these guidelines above all else:
- **Always be polite and respectful to others** and try to follow the advice of the moderators/collaborators/owners.
- **Only modify snippet files**, never modify the generated files in the `snippet_data` directory.
- **Use the snippet template** to create new snippets, ensure they have the correct name and are in the correct location.
- **Follow snippet format exactly**, otherwise your snippets will not be recognized correctly by the tools responsible for publishing them on the website. This includes such things as spacing and empty lines - if you accidentally make a mistake, consult the repository's [snippet template](snippet-template.md).
- **Snippets should solve real-world problems**, no matter how simple and should be abstract enough to be applied to different scenarios.
## Snippet creation
In order to create a new snippet, you should follow the steps below:
- Create a copy of the [snippet template](snippet-template.md) in the `snippets` directory.
- Change the name of the newly created file to the name of your snippet.
- Edit the file, adding your snippet based on the guidelines.
## Snippet guidelines
- Snippet must follow [these general writing guidelines](https://github.com/30-seconds/brand-and-design/blob/master/writing-guidelines.md).
- Snippets must have all their frontmatter sections (title, tags etc.) filled.
- Snippet titles must correspond to the filename and follow the language and repository's naming conventions.
- Snippet tags must be comma-separated, contain a primary tag as seen on the website as their first tag.
- Snippets must have their `firstSeen` dates formatted using [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601).
- Snippet descriptions must be short and to the point. Explain *what* the snippet does and detail *how* the snippet works and the language features used in it.
- Snippet code and examples must be enclosed in appropriate, language-tagged blocks as shown in the snippet template, be short and use modern techniques and features. Also make sure to test your code before submitting.
- If your snippet contains arguments with default parameters, explain what happens if they are omitted when calling the function and what the default case is. Specify default parameters for arguments only if necessary.
- If your snippet uses recursion, use the `recursion` tag and explain the base cases.
- Try to strike a balance between readability, brevity, and performance.
- Always use soft tabs (2 spaces), never hard tabs.
- Leave a single space after a comma (`,`) character (both in the description and code).
- Define multiple variables on the same line, if possible. Use meaningful names (e.g. `letter` instead of `lt`) and follow existing conventions as seen in other snippets. Do not use trailing or leading underscores in variable names.

395
git/LICENSE Normal file
View File

@ -0,0 +1,395 @@
Attribution 4.0 International
=======================================================================
Creative Commons Corporation ("Creative Commons") is not a law firm and
does not provide legal services or legal advice. Distribution of
Creative Commons public licenses does not create a lawyer-client or
other relationship. Creative Commons makes its licenses and related
information available on an "as-is" basis. Creative Commons gives no
warranties regarding its licenses, any material licensed under their
terms and conditions, or any related information. Creative Commons
disclaims all liability for damages resulting from their use to the
fullest extent possible.
Using Creative Commons Public Licenses
Creative Commons public licenses provide a standard set of terms and
conditions that creators and other rights holders may use to share
original works of authorship and other material subject to copyright
and certain other rights specified in the public license below. The
following considerations are for informational purposes only, are not
exhaustive, and do not form part of our licenses.
Considerations for licensors: Our public licenses are
intended for use by those authorized to give the public
permission to use material in ways otherwise restricted by
copyright and certain other rights. Our licenses are
irrevocable. Licensors should read and understand the terms
and conditions of the license they choose before applying it.
Licensors should also secure all rights necessary before
applying our licenses so that the public can reuse the
material as expected. Licensors should clearly mark any
material not subject to the license. This includes other CC-
licensed material, or material used under an exception or
limitation to copyright. More considerations for licensors:
wiki.creativecommons.org/Considerations_for_licensors
Considerations for the public: By using one of our public
licenses, a licensor grants the public permission to use the
licensed material under specified terms and conditions. If
the licensor's permission is not necessary for any reason--for
example, because of any applicable exception or limitation to
copyright--then that use is not regulated by the license. Our
licenses grant only permissions under copyright and certain
other rights that a licensor has authority to grant. Use of
the licensed material may still be restricted for other
reasons, including because others have copyright or other
rights in the material. A licensor may make special requests,
such as asking that all changes be marked or described.
Although not required by our licenses, you are encouraged to
respect those requests where reasonable. More considerations
for the public:
wiki.creativecommons.org/Considerations_for_licensees
=======================================================================
Creative Commons Attribution 4.0 International Public License
By exercising the Licensed Rights (defined below), You accept and agree
to be bound by the terms and conditions of this Creative Commons
Attribution 4.0 International Public License ("Public License"). To the
extent this Public License may be interpreted as a contract, You are
granted the Licensed Rights in consideration of Your acceptance of
these terms and conditions, and the Licensor grants You such rights in
consideration of benefits the Licensor receives from making the
Licensed Material available under these terms and conditions.
Section 1 -- Definitions.
a. Adapted Material means material subject to Copyright and Similar
Rights that is derived from or based upon the Licensed Material
and in which the Licensed Material is translated, altered,
arranged, transformed, or otherwise modified in a manner requiring
permission under the Copyright and Similar Rights held by the
Licensor. For purposes of this Public License, where the Licensed
Material is a musical work, performance, or sound recording,
Adapted Material is always produced where the Licensed Material is
synched in timed relation with a moving image.
b. Adapter's License means the license You apply to Your Copyright
and Similar Rights in Your contributions to Adapted Material in
accordance with the terms and conditions of this Public License.
c. Copyright and Similar Rights means copyright and/or similar rights
closely related to copyright including, without limitation,
performance, broadcast, sound recording, and Sui Generis Database
Rights, without regard to how the rights are labeled or
categorized. For purposes of this Public License, the rights
specified in Section 2(b)(1)-(2) are not Copyright and Similar
Rights.
d. Effective Technological Measures means those measures that, in the
absence of proper authority, may not be circumvented under laws
fulfilling obligations under Article 11 of the WIPO Copyright
Treaty adopted on December 20, 1996, and/or similar international
agreements.
e. Exceptions and Limitations means fair use, fair dealing, and/or
any other exception or limitation to Copyright and Similar Rights
that applies to Your use of the Licensed Material.
f. Licensed Material means the artistic or literary work, database,
or other material to which the Licensor applied this Public
License.
g. Licensed Rights means the rights granted to You subject to the
terms and conditions of this Public License, which are limited to
all Copyright and Similar Rights that apply to Your use of the
Licensed Material and that the Licensor has authority to license.
h. Licensor means the individual(s) or entity(ies) granting rights
under this Public License.
i. Share means to provide material to the public by any means or
process that requires permission under the Licensed Rights, such
as reproduction, public display, public performance, distribution,
dissemination, communication, or importation, and to make material
available to the public including in ways that members of the
public may access the material from a place and at a time
individually chosen by them.
j. Sui Generis Database Rights means rights other than copyright
resulting from Directive 96/9/EC of the European Parliament and of
the Council of 11 March 1996 on the legal protection of databases,
as amended and/or succeeded, as well as other essentially
equivalent rights anywhere in the world.
k. You means the individual or entity exercising the Licensed Rights
under this Public License. Your has a corresponding meaning.
Section 2 -- Scope.
a. License grant.
1. Subject to the terms and conditions of this Public License,
the Licensor hereby grants You a worldwide, royalty-free,
non-sublicensable, non-exclusive, irrevocable license to
exercise the Licensed Rights in the Licensed Material to:
a. reproduce and Share the Licensed Material, in whole or
in part; and
b. produce, reproduce, and Share Adapted Material.
2. Exceptions and Limitations. For the avoidance of doubt, where
Exceptions and Limitations apply to Your use, this Public
License does not apply, and You do not need to comply with
its terms and conditions.
3. Term. The term of this Public License is specified in Section
6(a).
4. Media and formats; technical modifications allowed. The
Licensor authorizes You to exercise the Licensed Rights in
all media and formats whether now known or hereafter created,
and to make technical modifications necessary to do so. The
Licensor waives and/or agrees not to assert any right or
authority to forbid You from making technical modifications
necessary to exercise the Licensed Rights, including
technical modifications necessary to circumvent Effective
Technological Measures. For purposes of this Public License,
simply making modifications authorized by this Section 2(a)
(4) never produces Adapted Material.
5. Downstream recipients.
a. Offer from the Licensor -- Licensed Material. Every
recipient of the Licensed Material automatically
receives an offer from the Licensor to exercise the
Licensed Rights under the terms and conditions of this
Public License.
b. No downstream restrictions. You may not offer or impose
any additional or different terms or conditions on, or
apply any Effective Technological Measures to, the
Licensed Material if doing so restricts exercise of the
Licensed Rights by any recipient of the Licensed
Material.
6. No endorsement. Nothing in this Public License constitutes or
may be construed as permission to assert or imply that You
are, or that Your use of the Licensed Material is, connected
with, or sponsored, endorsed, or granted official status by,
the Licensor or others designated to receive attribution as
provided in Section 3(a)(1)(A)(i).
b. Other rights.
1. Moral rights, such as the right of integrity, are not
licensed under this Public License, nor are publicity,
privacy, and/or other similar personality rights; however, to
the extent possible, the Licensor waives and/or agrees not to
assert any such rights held by the Licensor to the limited
extent necessary to allow You to exercise the Licensed
Rights, but not otherwise.
2. Patent and trademark rights are not licensed under this
Public License.
3. To the extent possible, the Licensor waives any right to
collect royalties from You for the exercise of the Licensed
Rights, whether directly or through a collecting society
under any voluntary or waivable statutory or compulsory
licensing scheme. In all other cases the Licensor expressly
reserves any right to collect such royalties.
Section 3 -- License Conditions.
Your exercise of the Licensed Rights is expressly made subject to the
following conditions.
a. Attribution.
1. If You Share the Licensed Material (including in modified
form), You must:
a. retain the following if it is supplied by the Licensor
with the Licensed Material:
i. identification of the creator(s) of the Licensed
Material and any others designated to receive
attribution, in any reasonable manner requested by
the Licensor (including by pseudonym if
designated);
ii. a copyright notice;
iii. a notice that refers to this Public License;
iv. a notice that refers to the disclaimer of
warranties;
v. a URI or hyperlink to the Licensed Material to the
extent reasonably practicable;
b. indicate if You modified the Licensed Material and
retain an indication of any previous modifications; and
c. indicate the Licensed Material is licensed under this
Public License, and include the text of, or the URI or
hyperlink to, this Public License.
2. You may satisfy the conditions in Section 3(a)(1) in any
reasonable manner based on the medium, means, and context in
which You Share the Licensed Material. For example, it may be
reasonable to satisfy the conditions by providing a URI or
hyperlink to a resource that includes the required
information.
3. If requested by the Licensor, You must remove any of the
information required by Section 3(a)(1)(A) to the extent
reasonably practicable.
4. If You Share Adapted Material You produce, the Adapter's
License You apply must not prevent recipients of the Adapted
Material from complying with this Public License.
Section 4 -- Sui Generis Database Rights.
Where the Licensed Rights include Sui Generis Database Rights that
apply to Your use of the Licensed Material:
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
to extract, reuse, reproduce, and Share all or a substantial
portion of the contents of the database;
b. if You include all or a substantial portion of the database
contents in a database in which You have Sui Generis Database
Rights, then the database in which You have Sui Generis Database
Rights (but not its individual contents) is Adapted Material; and
c. You must comply with the conditions in Section 3(a) if You Share
all or a substantial portion of the contents of the database.
For the avoidance of doubt, this Section 4 supplements and does not
replace Your obligations under this Public License where the Licensed
Rights include other Copyright and Similar Rights.
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
c. The disclaimer of warranties and limitation of liability provided
above shall be interpreted in a manner that, to the extent
possible, most closely approximates an absolute disclaimer and
waiver of all liability.
Section 6 -- Term and Termination.
a. This Public License applies for the term of the Copyright and
Similar Rights licensed here. However, if You fail to comply with
this Public License, then Your rights under this Public License
terminate automatically.
b. Where Your right to use the Licensed Material has terminated under
Section 6(a), it reinstates:
1. automatically as of the date the violation is cured, provided
it is cured within 30 days of Your discovery of the
violation; or
2. upon express reinstatement by the Licensor.
For the avoidance of doubt, this Section 6(b) does not affect any
right the Licensor may have to seek remedies for Your violations
of this Public License.
c. For the avoidance of doubt, the Licensor may also offer the
Licensed Material under separate terms or conditions or stop
distributing the Licensed Material at any time; however, doing so
will not terminate this Public License.
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
License.
Section 7 -- Other Terms and Conditions.
a. The Licensor shall not be bound by any additional or different
terms or conditions communicated by You unless expressly agreed.
b. Any arrangements, understandings, or agreements regarding the
Licensed Material not stated herein are separate from and
independent of the terms and conditions of this Public License.
Section 8 -- Interpretation.
a. For the avoidance of doubt, this Public License does not, and
shall not be interpreted to, reduce, limit, restrict, or impose
conditions on any use of the Licensed Material that could lawfully
be made without permission under this Public License.
b. To the extent possible, if any provision of this Public License is
deemed unenforceable, it shall be automatically reformed to the
minimum extent necessary to make it enforceable. If the provision
cannot be reformed, it shall be severed from this Public License
without affecting the enforceability of the remaining terms and
conditions.
c. No term or condition of this Public License will be waived and no
failure to comply consented to unless expressly agreed to by the
Licensor.
d. Nothing in this Public License constitutes or may be interpreted
as a limitation upon, or waiver of, any privileges and immunities
that apply to the Licensor or You, including from the legal
processes of any jurisdiction or authority.
=======================================================================
Creative Commons is not a party to its public
licenses. Notwithstanding, Creative Commons may elect to apply one of
its public licenses to material it publishes and in those instances
will be considered the “Licensor.” The text of the Creative Commons
public licenses is dedicated to the public domain under the CC0 Public
Domain Dedication. Except for the limited purpose of indicating that
material is shared under a Creative Commons public license or as
otherwise permitted by the Creative Commons policies published at
creativecommons.org/policies, Creative Commons does not authorize the
use of the trademark "Creative Commons" or any other trademark or logo
of Creative Commons without its prior written consent including,
without limitation, in connection with any unauthorized modifications
to any of its public licenses or any other arrangements,
understandings, or agreements concerning use of licensed material. For
the avoidance of doubt, this paragraph does not form part of the
public licenses.
Creative Commons may be contacted at creativecommons.org.

26
git/README.md Normal file
View File

@ -0,0 +1,26 @@
[![Logo](/logo.png)](https://30secondsofcode.org/git/p/1)
# 30 seconds of code
> Short git code snippets for all your development needs
* Visit [our website](https://30secondsofcode.org) to view our snippet collection.
* Use the [Search page](https://30secondsofcode.org/search) to find snippets that suit your needs. You can search by name, tag, language or using a snippet's description. Just start typing a term and see what comes up.
* Browse the [Git Snippet collection](https://30secondsofcode.org/git/p/1) to see all the snippets in this project or click individual tags at the top of the same page to narrow down your search to a specific tag.
* Click on each snippet card to view the whole snippet, including code, explanation and examples.
* You can use the button at the bottom of a snippet card to copy the code to clipboard.
* If you like the project, give it a star. It means a lot to the people maintaining it.
## Want to contribute?
* If you want to help us improve, take a minute to read the [Contribution Guidelines](/CONTRIBUTING.md) first.
* Use the [Snippet Template](/snippet-template.md) to add new snippets to the collection.
* If you find a problem with a specific snippet, please [open an issue](https://github.com/30-seconds/30-seconds-of-git/issues/new).
* If you find a problem with the website, please [report it in the web repository](https://github.com/30-seconds/30-seconds-web/issues/new).
## Credits
* This repository is maintained by the [30 seconds of code organization on GitHub](https://github.com/30-seconds).
* All snippets are licensed under the CC-BY-4.0 License, unless explicitly stated otherwise.
* Logos, names and trademarks are not to be used without the explicit consent of the owners of the 30 seconds of code GitHub organization.
* Our website is powered by [Netlify](https://www.netlify.com/), [Next.js](https://nextjs.org/) & [GitHub](https://github.com/).

BIN
git/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

22
git/snippet-template.md Normal file
View File

@ -0,0 +1,22 @@
---
title: Snippet name
type: snippet
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`
```

View File

@ -0,0 +1,22 @@
---
title: Add a submodule
type: snippet
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,20 @@
---
title: Apply the latest stash
type: snippet
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,20 @@
---
title: Apply a stash
type: snippet
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,21 @@
---
title: Autocorrect git commands
type: snippet
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,33 @@
---
title: Automatically find the commit that introduced a bug
type: snippet
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,22 @@
---
title: Automate upstream branch creation
type: snippet
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,21 @@
---
title: Find branches containing a commit
type: snippet
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,21 @@
---
title: Find branches not containing a commit
type: snippet
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,21 @@
---
title: Change the remote URL
type: snippet
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,21 @@
---
title: Clone missing submodules
type: snippet
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,26 @@
---
title: Clone a repository
type: snippet
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,24 @@
---
title: Change the last commit's author
type: snippet
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,23 @@
---
title: Create a commit by a different author
type: snippet
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,21 @@
---
title: Add a commit message template
type: snippet
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,22 @@
---
title: Commit without running git hooks
type: snippet
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,28 @@
---
title: Configure git user information
type: snippet
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,22 @@
---
title: Copy a file from another branch
type: snippet
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,25 @@
---
title: Create a new branch
type: snippet
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,22 @@
---
title: Create a commit
type: snippet
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,20 @@
---
title: Create an empty commit
type: snippet
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,25 @@
---
title: Create a fixup commit
type: snippet
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,26 @@
---
title: Create a new repository
type: snippet
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,20 @@
---
title: Get the current branch name
type: snippet
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,20 @@
---
title: Delete a branch
type: snippet
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,31 @@
---
title: Delete detached branches
type: snippet
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,32 @@
---
title: Delete merged branches
type: snippet
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,20 @@
---
title: Delete a remote branch
type: snippet
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,20 @@
---
title: Delete a stash
type: snippet
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,21 @@
---
title: Delete all stashes
type: snippet
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,27 @@
---
title: Delete a submodule
type: snippet
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,21 @@
---
title: View difference between two branches
type: snippet
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,25 @@
---
title: Disable fast forward merging by default
type: snippet
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,20 @@
---
title: Discard uncommitted changes
type: snippet
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,20 @@
---
title: Discard untracked changes
type: snippet
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,20 @@
---
title: Edit git configuration file
type: snippet
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,19 @@
---
title: Fetch latest changes from remote
type: snippet
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,24 @@
---
title: Find lost files
type: snippet
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,27 @@
---
title: Update remote branch after rewriting history
type: snippet
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,28 @@
---
title: Perform an interactive rebase
type: snippet
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,21 @@
---
title: Configure line endings
type: snippet
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,24 @@
---
title: List all git aliases
type: snippet
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,21 @@
---
title: Lists all stashes
type: snippet
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,34 @@
---
title: Manually find the commit that introduced a bug
type: snippet
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,24 @@
---
title: Merge a branch and create a merge commit
type: snippet
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,22 @@
---
title: Merge a branch
type: snippet
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,31 @@
---
title: Move commits from master to a new branch
type: snippet
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,20 @@
---
title: Optimize the local repository
type: snippet
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,28 @@
---
title: Pick changes from one or more commits
type: snippet
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,21 @@
---
title: Pull all submodules from remote
type: snippet
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,21 @@
---
title: Pull latest changes from remote
type: snippet
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,31 @@
---
title: Purge a file from history
type: snippet
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,21 @@
---
title: Push local changes to remote
type: snippet
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,28 @@
---
title: Rebase onto another branch
type: snippet
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,23 @@
---
title: Remove a file from the last commit
type: snippet
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,21 @@
---
title: Rename a branch
type: snippet
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,29 @@
---
title: Rename remote branch
type: snippet
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,26 @@
---
title: Reset master to match remote
type: snippet
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,22 @@
---
title: Restore a deleted file
type: snippet
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,25 @@
---
title: Rewind back n commits
type: snippet
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,25 @@
---
title: Rewind back to a specific commit
type: snippet
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,29 @@
---
title: Create a stash
type: snippet
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,25 @@
---
title: Set default push branch name
type: snippet
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,20 @@
---
title: Configure the git text editor
type: snippet
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,24 @@
---
title: View branches sorted by date
type: snippet
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,27 @@
---
title: Add files to the staging area
type: snippet
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,20 @@
---
title: Switch to a branch
type: snippet
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,21 @@
---
title: Return to previous branch
type: snippet
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,20 @@
---
title: Undo a commit
type: snippet
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,20 @@
---
title: Undo the last commit
type: snippet
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,28 @@
---
title: Remove files from the staging area
type: snippet
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,24 @@
---
title: Edit the last commit
type: snippet
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,22 @@
---
title: Change the last commit's message
type: snippet
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,23 @@
---
title: View local branches
type: snippet
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,24 @@
---
title: View a summary of changes between two commits
type: snippet
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,22 @@
---
title: View a visual graph of the repository
type: snippet
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,24 @@
---
title: View commits by author
type: snippet
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,24 @@
---
title: View commits that manipulated a specific string
type: snippet
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,31 @@
---
title: View commits in a specific date range
type: snippet
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,21 @@
---
title: View a short summary of commits without merge commits
type: snippet
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,22 @@
---
title: View a short summary of commits
type: snippet
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,25 @@
---
title: View differences in changes
type: snippet
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,24 @@
---
title: View last commit
type: snippet
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,23 @@
---
title: View merged branches
type: snippet
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,21 @@
---
title: View the remote URL
type: snippet
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,33 @@
---
title: View current status
type: snippet
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,29 @@
---
title: View "undo" history
type: snippet
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
```