Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn some existing git snippets into stories #1935

Merged
merged 1 commit into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions snippets/git/s/automatic-push-upstream.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
---
title: Automate upstream branch creation
type: snippet
title: "Tip: Automate upstream branch creation"
shortTitle: Automate upstream branch creation
type: tip
language: git
tags: [configuration,repository]
author: chalarangelo
cover: messy-computer
dateModified: 2022-10-19T05:00:00-04:00
excerpt: Effortlessly create upstream branches on push by enabling a simple git config setting.
dateModified: 2023-05-21T05: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.
Manually creating upstream branches on push can be a tedious task. Luckily, Git provides a way to automate this process. You can use `git config` to enable automatic upstream branch creation on push:

```shell
git config [--global] --add --bool
```

```shell
git config --global --add --bool
git config [--global] --add --bool push.autoSetupRemote true
# `git push` will automatically create new branches, if they don't exist
```

Using `push.autoSetupRemote` will automatically create a new branch on the remote repository, if it doesn't exist. Workflows that benefit most from this setup are ones where local branches are expected to have the same name as their remote counterparts. You can use the `--global` flag to enable this setting globally on your machine.
24 changes: 12 additions & 12 deletions snippets/git/s/view-undo-history.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
---
title: View "undo" history
type: snippet
type: story
language: git
tags: [repository,branch]
author: chalarangelo
cover: rock-climbing
dateModified: 2021-04-13T21:10:59+03:00
excerpt: Learn how to view your "undo" history using git reflog and reset your repository to a previous state.
dateModified: 2023-05-21T21:10:59+03:00
---

View git's reference logs. This is especially useful for finding references that don't show up in commit history.
Sometimes, `git log` doesn't cut it, especially for commands that don't show up in your commit history. Fortunately, there's a way to view your "undo" history. `reflog` is basically your safety net after running "scary" commands like `git rebase`. It allows you to see not only the commits you made, but each of the actions that led you there.

- 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.
To view you "undo" history, you can use `git reflog`, which displays the git reference log:

```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
```

After you've found the commit you want, you can use `git reset` to go back to it.

```shell
git reset --hard 3050fc0de # Go back to the commit with the given hash
```