Branches? We Don't Need No Stinking Branches! - Getting Good With Git
Aside from the git example that I’ve linked in the past I also enjoy Oh Shit, Git!?! quite a bit for the fact that it’s both accepting that people will mess up their repository in some way and also ready and able to help out. But, from my experience with git, it’s best to keep a cool head.
Pierce the vale
The feature I’m working on right now is adding some information from vale to the bottom of my posts. This is a cross-domain activity but, right now, I’ve created a branch because I’ve added several files that will need to be hit during the pipeline to make this magic happen. There will be an entire post on vale coming soon.
Branching: Fun and Easy
Git is clever in that there is a local repository and a remote repository. I tend to not think of it that way but it likes to remind me.
git branch vale-info
# This just created a branch! Easy!
git switch vale-info
# This just switched to that branch! Easy!!
git add -A
# This just added all the changes!
git commit -m "Hey, I'm coding here!"
# it's midnight but I'm not a cowboy
So here is where I got reminded. git push
at this stage pushes back, helpfully, with the error message
git push
fatal: The current branch vale-info has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin vale-info
We’ve got a version system that wants to have a remote set, so oblige it.
git push --set-upstream origin vale-info
Enumerating objects: 70, done.
Counting objects: 100% (70/70), done.
Delta compression using up to 8 threads
Compressing objects: 100% (60/60), done.
Writing objects: 100% (64/64), 35.68 KiB | 8.92 MiB/s, done.
Total 64 (delta 7), reused 0 (delta 0), pack-reused 0
remote: Analyzing objects... (64/64) (350 ms)
remote: Storing packfile... done (50 ms)
remote: Storing index... done (49 ms)
To https://dev.azure.com/org/marktoso-site/_git/marktoso-site
* [new branch] vale-info -> vale-info
Branch 'vale-info' set up to track remote branch 'vale-info' from 'origin'.
Nice and easy. I’ll prove it to you.
We do need stinkin branches!
Indeed. It may also be worth branching earlier than you think. I started working on this vale feature and realized that I’m just cluttering up everything, which isn’t a huge problem, but am now going to commit some slightly broken stuff, which may be a problem. I’ll take that problem as it comes but my life could have been much easier had I just branched sooner. I now need to switch back to main
to then add this post in here and hit publish.
Branching is about logically separating your work up. It becomes blatantly obvious when you have several people working on one codebase but when you’re on your own it may seem almost silly. It isn’t. It’s building good habits.
git add content/posts/branches-we-dont-need-no-stinkin-branches.md
git add static/images/stinkin-branches/branches-azuredevops.jpg
git commit -m "stinkin branches post is done"
But I’m actually not done with the post so I’ll need to save it again and use git ammend
.
git add content/posts/branches-we-dont-need-no-stinkin-branches.md
git commit --amend --no-edit
git switch main
git merge vale-info #bring this branch back in to main
git push
And now it’s all fine! Or, it will be all fine.
./content/posts/branches-we-dont-need-no-stinkin-branches.md 10:56 warning Use first person (such as ' I Microsoft.FirstPerson ') sparingly. 10:263 warning Use first person (such as Microsoft.FirstPerson 'my') sparingly. 13:13 warning Use first person (such as Microsoft.FirstPerson 'I'm') sparingly. 13:129 warning Use first person (such as Microsoft.FirstPerson 'my') sparingly. 16:75 warning Use first person (such as ' I Microsoft.FirstPerson ') sparingly. 16:134 warning Use first person (such as Microsoft.FirstPerson 'me') sparingly. 27:17 warning Use first person (such as ' I Microsoft.FirstPerson ') sparingly. 35:1 warning Try to avoid using Microsoft.We first-person plural like 'We'. 54:5 warning Try to avoid using Microsoft.We first-person plural like 'We'. 54:31 warning Don't use end punctuation in Microsoft.HeadingPunctuation headings. 55:121 warning Use first person (such as Microsoft.FirstPerson 'I'm') sparingly. 55:302 warning Use first person (such as Microsoft.FirstPerson 'my') sparingly. 55:341 warning Use first person (such as ' I Microsoft.FirstPerson ') sparingly. 55:365 warning Use first person (such as ' I Microsoft.FirstPerson ') sparingly. 63:5 warning Use first person (such as Microsoft.FirstPerson 'I'm') sparingly. 73:210 warning Use first person (such as ' I Microsoft.FirstPerson ') sparingly.✖ 0 errors, 16 warnings and 0 suggestions in 1 file.