Mirror of
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(content): write recommended git config post (#175)

* feat(content): write recommended git config post

* fix: suggestions

authored by

Felix Schneider and committed by
GitHub
d3cab027 0ea7cbd9

+189
public/blog/recommended-git-config.jpg

This is a binary file and will not be displayed.

+180
src/content/docs/blog/recommended-git-config.mdx
··· 1 + --- 2 + title: Recommended Git Config 3 + date: 2026-02-27 4 + description: There are some quality of life configurations for git that can improve your workflow significantly. 5 + tags: 6 + - Education 7 + authors: 8 + - trueberryless 9 + cover: 10 + alt: A monochrome image of a dark room, featuring deep shadows and minimal light with abstract circles and shapes. 11 + image: ../../../../public/blog/recommended-git-config.jpg 12 + giscus: true 13 + --- 14 + 15 + import { Tabs, TabItem } from '@astrojs/starlight/components'; 16 + 17 + In order to optimize my git workflow, specifically for GitHub, I present you with some configs and tricks that I set up. 18 + 19 + ## Automatic rebase 20 + 21 + Since I like to keep my commit history linear, I personally prefer to rebase instead of merge when I pull new changes from the remote repository. This means that if I run `git pull`, it will not perform a `fetch` and `merge` but rather a `fetch` followed by a `rebase`, which results in my local commits being automatically included on top of the remote commits coming in. That way, I avoid having merge commits that would IMHO pollute the history. 22 + 23 + If you want to try this out yourself, use the `--rebase` parameter on `pull` like that: 24 + 25 + ```bash 26 + git pull --rebase 27 + ``` 28 + 29 + If you feel happy with this workflow, you can set it in your global config, so you don't need to include the `--rebase` option anymore: 30 + 31 + ```bash 32 + git config --global pull.rebase true 33 + ``` 34 + 35 + ## Default branch: `main` 36 + 37 + By default, git often initializes new repositories with `master` as the primary branch. However, most modern platforms (especially GitHub) have moved towards using `main`. Instead of renaming your branch every time you run `git init`, you can tell git to use `main` globally by default: 38 + 39 + ```bash 40 + git config --global init.defaultBranch main 41 + ``` 42 + 43 + ## Adding co-authors 44 + 45 + I really like to credit people who contributed in any way to my commits. What I find annoying, however, is that you have to know the GitHub email address of the user you want to [Co-author](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors). I used to go to the people's profile, search for a recent commit they made and appending `.patch` to the GitHub commit URL. In the diff that you get this way, you can manually extract the email of the user. But why should I manually do this 1min work if I could spend 10h automating it? 46 + 47 + <div style="display: flex; justify-content: space-evenly; align-items: flex-start; gap: 2rem;"> 48 + <img src="https://imgs.xkcd.com/comics/automation.png" alt="An xkcd comic strip titled 'Automation' exploring the discrepancy between theoretical expectation and reality. In the 'THEORY' panel, a graph shows a brief spike for 'WRITING CODE' before a sharp decline as 'AUTOMATION TAKES OVER,' leaving vast 'FREE TIME.' In the 'REALITY' panel, the 'WRITING CODE' spike leads into a fluctuating line of 'DEBUGGING' and 'RETHINKING' that eventually climbs steadily upward as 'ONGOING DEVELOPMENT,' leaving 'NO TIME FOR ORIGINAL TASK ANYMORE' as the workload permanently increases beyond the original baseline." /> 49 + <img src="https://imgs.xkcd.com/comics/is_it_worth_the_time.png" alt="An xkcd comic titled 'Is It Worth the Time?' featuring a grid that calculates the time-saving break-even point over five years. The horizontal axis lists task frequency (50/day to yearly) and the vertical axis lists time saved per task (1 second to 1 day). Each cell shows the maximum time you should spend automating; for instance, saving 30 seconds on a daily task justifies 12 hours of work, while saving 1 second on a yearly task justifies only 5 seconds. The table uses various units like minutes, hours, days, weeks, and months to illustrate the limits of efficient automation." /> 50 + </div> 51 + 52 + Sorry, I just had to include those two [legendary](https://xkcd.com/1319/) [xkcds](https://xkcd.com/1205/) in here. 53 + 54 + --- 55 + 56 + So I created a little bash script which simplifies adding Co-authors to your commits. All you need is `gh` and `jq` installed, and the little bash script below. 57 + 58 + <Tabs> 59 + <TabItem label="MacOS"> 60 + 61 + ```bash 62 + brew install gh jq 63 + ``` 64 + 65 + </TabItem> 66 + <TabItem label="Linux"> 67 + 68 + ```bash 69 + sudo apt install gh jq 70 + ``` 71 + 72 + </TabItem> 73 + <TabItem label="Windows"> 74 + 75 + :::note 76 + Just use WSL please. 77 + ::: 78 + 79 + </TabItem> 80 + </Tabs> 81 + 82 + Save this bash script as `git-ucommit` to a folder that is in your `$PATH` (like `~/bin` or `/usr/local/bin`) and make it executable with `chmod +x ~/bin/git-ucommit`: 83 + 84 + ```bash 85 + // ~/bin/git-ucommit 86 + #!/usr/bin/env bash 87 + 88 + # Check for dependencies 89 + if ! command -v gh &> /dev/null || ! command -v jq &> /dev/null; then 90 + echo "Error: 'gh' (GitHub CLI) and 'jq' are required." 91 + exit 1 92 + fi 93 + 94 + args=() 95 + usernames=() 96 + message="" 97 + 98 + # Parse arguments 99 + while [[ $# -gt 0 ]]; do 100 + case "$1" in 101 + -u|--user) 102 + usernames+=("$2") 103 + shift 2 104 + ;; 105 + -m|--message) 106 + message="$2" 107 + shift 2 108 + ;; 109 + *) 110 + args+=("$1") 111 + shift 112 + ;; 113 + esac 114 + done 115 + 116 + trailer_args=() 117 + 118 + # Resolve GitHub usernames to Co-authored-by trailers 119 + for user in "${usernames[@]}"; do 120 + user_json=$(gh api users/"$user" 2>/dev/null) 121 + if [[ $? -ne 0 ]]; then 122 + echo "Warning: Could not find GitHub user '$user'. Skipping." 123 + continue 124 + fi 125 + 126 + name=$(echo "$user_json" | jq -r '.name // .login') 127 + id=$(echo "$user_json" | jq -r '.id') 128 + email="$id+$user@users.noreply.github.com" 129 + 130 + trailer_args+=(--trailer "Co-authored-by: $name <$email>") 131 + done 132 + 133 + # Execute the commit 134 + if [[ -n "$message" ]]; then 135 + final_msg=$(echo -e "$message" | git interpret-trailers "${trailer_args[@]}") 136 + git commit "${args[@]}" -m "$final_msg" 137 + else 138 + # No -m flag? Inject trailers and open the editor 139 + git commit "${args[@]}" "${trailer_args[@]}" -e 140 + fi 141 + ``` 142 + 143 + Since the file name starts with `git-`, you do not even need to create a git alias, as it is smart enough to detect your executable and just allows you run: 144 + 145 + ```bash 146 + git ucommit -m "fix: suggestions" -u trueberryless -u delucis 147 + ``` 148 + 149 + :::note 150 + Unfortunately, I didn't find a way to add those options to the default `commit` command, so I prepended the letter `u` to it, which stands for users. 151 + ::: 152 + 153 + I myself integrated this functionality into my [nix-darwin](https://github.com/nix-darwin/nix-darwin) setup. Check out my [Nix module](https://github.com/trueberryless/nix/blob/a1be76b4723b0061c34cca1063a477774156ce0a/modules/git-tools.nix) if you can profit from this setup. 154 + 155 + ## Summary 156 + 157 + **🔄 Automatic Rebase on Pull** 158 + > `git config --global pull.rebase true` 159 + > 160 + > Sets your global configuration to perform a rebase instead of a merge when pulling. This keeps your git history linear and avoids unnecessary merge commits. 161 + 162 + **🌱 Modern Default Branch** 163 + > `git config --global init.defaultBranch main` 164 + > 165 + > Ensures every new local repository you initialize starts with `main` instead of `master`, aligning your local environment with GitHub's defaults. 166 + 167 + **👥 Simplified Co-Authoring** 168 + > `git ucommit -m "message" -u <username>` 169 + > 170 + > Uses a custom bash script alongside `gh` and `jq` to automatically resolve GitHub usernames to the correct "Co-authored-by" trailers, saving you from manual email lookups. 171 + 172 + ## Resources 173 + 174 + Here are some helpful resources for optimizing your Git and GitHub workflow: 175 + 176 + - [GitHub CLI (gh) Documentation](https://cli.github.com/manual/) 177 + - [Creating a commit with multiple authors](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors) 178 + - [Git Interpret Trailers Documentation](https://git-scm.com/docs/git-interpret-trailers) 179 + 180 + That's it! With these tweaks, your local environment stays modern, your history stays clean, and giving credit to your collaborators becomes a breeze. Happy coding!
+9
src/content/docs/credits.mdx
··· 63 63 64 64 <ImageCreditsSection> 65 65 <ImageCredit 66 + image="/public/blog/recommended-git-config.jpg" 67 + title="A Black Background With Lots of Circles and Bubbles" 68 + author="Aedrian Salazar" 69 + authorUrl="https://unsplash.com/@aedrian" 70 + sourceUrl="https://unsplash.com/photos/a-black-background-with-lots-of-circles-and-bubbles-HBD5k7sA3MQ" 71 + usedOn="Recommended Git Config" 72 + usedOnUrl="/blog/recommended-git-config" 73 + /> 74 + <ImageCredit 66 75 image="/public/blog/authors/artificial-intelligence.jpg" 67 76 title="A Brain Displayed with Glowing Blue Lines" 68 77 author="Shubham Dhage"