From 2efaf270664be7e9022afa41792263b1e4cdb99d Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sun, 26 Oct 2025 17:58:42 -0500 Subject: [PATCH] Add Tell gh What The Default Repo Is as a Git TIL --- README.md | 3 +- git/tell-gh-what-the-default-repo-is.md | 38 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 git/tell-gh-what-the-default-repo-is.md diff --git a/README.md b/README.md index 5d51813..c8e450e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1667 TILs and counting..._ +_1668 TILs and counting..._ See some of the other learning resources I work on: @@ -415,6 +415,7 @@ If you've learned something here, support my efforts writing daily TILs by - [Stashing Untracked Files](git/stashing-untracked-files.md) - [Switch To A Recent Branch With FZF](git/switch-to-a-recent-branch-with-fzf.md) - [Transition A Branch From One Base To Another](git/transition-a-branch-from-one-base-to-another.md) +- [Tell gh What The Default Repo Is](git/tell-gh-what-the-default-repo-is.md) - [Turn Off The Output Pager For One Command](git/turn-off-the-output-pager-for-one-command.md) - [Two Kinds Of Dotted Range Notation](git/two-kinds-of-dotted-range-notation.md) - [Unstage Changes Wih Git Restore](git/unstage-changes-with-git-restore.md) diff --git a/git/tell-gh-what-the-default-repo-is.md b/git/tell-gh-what-the-default-repo-is.md new file mode 100644 index 0000000..8896b92 --- /dev/null +++ b/git/tell-gh-what-the-default-repo-is.md @@ -0,0 +1,38 @@ +# Tell gh What The Default Repo Is + +I recently forked [dkarter/dotfiles](https://github.com/dkarter/dotfiles) as a +way of bootstrapping a robust dotfile config for a new machine that I could +start making customizations to. I'm maintaining a `my-dotfiles` branch and keep +things in sync with the original upstream repo. + +When trying to go to *my* fork of the repo +([jbranchaud/dotfiles](https://github.com/jbranchaud/dotfiles)) in the web with +the `gh` CLI tool, I ran into a weird issue. It was instead opening up to +`dkarter/dotfiles`. + +`gh` was under the wrong impression which repo should be considered the default. +To clarify things for `gh`, there is a command to set the default repo. + +```bash +$ gh repo set-default jbranchaud/dotfiles +✓ Set jbranchaud/dotfiles as the default repository for the current directory +``` + +Now when I run `gh repo view --web`, it opens the browser to my fork of the +dotfiles. + +But where does this setting live? + +Opening this repo's `.git/config` file I can see a section for the `origin` +remote that includes a new line for `gh-resolved`. This being set to `base` +tells `gh` that this remote is the one to treat as the default repo. + +``` +[remote "origin"] + url = git@github.com:jbranchaud/dotfiles.git + fetch = +refs/heads/*:refs/remotes/origin/* + gh-resolved = base + +``` + +See `gh repo set-default --help` for more details.