Skip to content

git

git over here and git it when the git is good and hot🔥

How does this wizardy work? 🧙‍♂️

Isn't it clear? Black magic 🤫

I've been working on getting better git hygiene and not commit everything to main so a little trial by fire is necessary! I first setup branch protection on main to disable push and enabled pull request merge. My CI / CD pipeline is currently set to build on - push to main.

I'm a 🐥 and only set up branch protection on one of the repos until I master this flow and my pipeline builds again

If you are seeing this post on the main blog I merged from drafts and built successfully inside CI / CD

Gotta be cli

I can't have myself dealing with the web UI it breaks my flow of code editor | save -> terminal | commit / push. The less I need to touch my mouse the better hence why I prefer a tiling window manager like i3 my boiler config is over here.

A lot of the documentation and videos rely on the web UI for GitHub, Gitea, and other Git platforms... I'm not having that! Keep it in the terminal. So I'm going to write this document as I wrap my tiny mind around git and the command line. Side note, I don't really use GitHub so I wont be focusing on the gh cli tool thats integrated into GitHub.

Codeberg | Forgejo

Most of my work is hosted privately on a local Forgejo code forge that was migrated from my old Gitea | 🫡 gone but not forgotten | server, but I've been curious about the codeberg-cli tool since its now compatible across both Codeberg and Forgejo.

I'm going to focus on the standard git command from the command line but on my blog I've recently set up "tabbed blocks" for code for examples. In the same space I can cram related code examples in tabs, so there's a good chance I will have both codeberg-cli and straight git command examples here.

Hat tip to Julia Evans How Git Works and all the great zines they put together. A few of these reference zines helped me big time!

Note: If you plan to have signed merges you must host your own Gitea or Forgejo instance. Also if you want to preform merge requests from the command line you need to setup your git platforms default tooling like gh - GitHub, berg - Codeberg, tea - Gitea. You are unable to finish the whole process just using the git command. I've got a quick tea reference doc over here for setup and auth. tea works for both Gitea and Codeberg. I can't seem to finish a merge request with the berg tool but the problem is probably in chair, not with berg itself.

MY STATS!

Be clear up front how you are going to handle pull requests if accepting them because your actions on repos effect other peoples glorious stats ratings ⭐️⭐️⭐️ | good person 👍️

Reading over David Rolsky's post here made me reconsider how I setup repositories. I know public collaboration is cool but some repos don't really need to be even though they can surely be public. A nice common ground I feel could be ActivityPub comments integrated into a static site to have engagement rather than pull requests for certain repos of content. 🤓 pushes up glagges This is far superior to traditional methods because we can use decentralization | federation | and encrypted and and an mutter mutter privacy mutter nerrrd...

If interested im working on ActivityPub comments | static dream where I setup comments through a Mastodon instance that I control.

The pull Request

Okay I made a branch called draft where I edit posts and version control them. When they are ready for consumption I need to push them back to main but your branch protection denies this from happening now. So you git add . | git commit -m "foo comment" | and git push back to your draft branches head. This time your console spits back a new message about creating a pull request.

remote: Create a new pull request for 'draft':
remote:   https://codeberg.org/noflcl/mkdocs/compare/main...draft
remote:
To codeberg.org:noflcl/mkdocs.git
   ce0e245..df3a899  draft -> draft

Where do you go from here? The link in your git output takes you to Codeberg's page where you can finish up the pull request and merge from the web UI which will get you where you need to be... But NO web UI! and the pull / merge requests aren't signed and we can't have that! BRAKES! 😟 turns out if your're are on hosted git solution like Gitea, Codeberg, Forgejo this isn't something that can change. You need to be in control of the git server so you can set a global signing key and get your green locks back🤩

Manage pull From cli

This is where the git command utility falls down and makes you rely on the platform tool. Most platform tools are almost command identical which makes things really easy.

tea pull create --title "PR title" --description "PR description" --head feature/new-feature --base main

You can now git checkout main, grab your PRs id with tea pull list and review your pull request with tea pull review PR_ID

merge it good

If you are happy with the changes from the code submitted you can merge it back into main tea pull merge --title "testing merge cli" --message "testing description" PR_ID

All These Rules!

Lets get into the weeds here and try to untangle the language that is git.

autosetupmerge - controls whether git branch and git checkout -b imply the --track option, i.e. with your setting of always. - git checkout branchname, if branchname exists on a remote but not locally, will create branchname tracking its remote counterpart - git checkout -b newbranch will create a new branch newbranch tracking whichever branch you had checked out before issuing this command

autosetuprebase - controls whether new branches should be set up to be rebased upon git pull, i.e. your setting of always will result in branches being set up such that git pull always performs a rebase, not a merge. (Be aware that existing branches retain their configuration when you change this option.)

It makes perfect sense to have both autosetupmerge | autosetuprebase = always

Coles Notes

You can view the condensed notes on my blog under documentation section. I keep short write ups, documenting commands, and code under there. My blog is the full recipe site and the Docs are the ↪️ jump to recipe for my git short.