February 12, 2023Multiline Commit Messages With `git commit -mWhen you execute git commit on the command line, your specified editor opens and you can create an expressive title and a longer description. That is probably nothing new. You are probably also aware of the shortcut git commit -m <message>, which skips the step with the editor. But there is only room for the title, right? Nope, this is not true. one way It turns out you can use -m multiple times....
January 19, 2023A Special Tool for Special Occasions: The Git Worktree CommandWhat is the issue? Working with branches is fine, as long as you are able to work on one only, or at least have the time to wrap up your work and commit some self-contained and complete state before switching to the next branch. If you cannot complete your work, it gets messy. Now, you can either use git stash create a work-in-progress(WIP) commit just keep the modified or new files, and try to work around them and to not commit them by accident git clone your repository into another directory I have done all of them, and they all have their downsides....
September 30, 2022How to Apply Git Log and Git Grep Only for a Specific File TypeToday I wanted to check how the UPDATE statement was used in already deleted SQL patch files. Usually I do a git log -p and then use the interactive search in less via /, but in this case there were too many hits from Python files, so I wanted to restrict my search to SQL files only. Turns out you can pass in the file type via … git log -p -- '*sql' And then use the interactive search....
March 10, 2022How to Update a Force Pushed Remote BranchImagine your colleague works on a new feature, and you have checked out their branch for a local review, and after an initial round of feedback and fixes, your colleague performs a git push --force to the remote branch. When you just do a git pull, you’ll end up in a mess like this… $ git pull remote: Enumerating objects: 19, done. remote: Counting objects: 100% (19/19), done. remote: Compressing objects: 100% (11/11), done....
November 5, 2021Migrate a Repository From Bazaar to GitBazaar is a distributed version control system (VCS), developed by Canonical. For a long time, Bazaar was the only supported VCS on Launchpad. Launchpad is a code hosting platform, similar to the now prevalent GitHub, and while open to the public, nowadays it is mostly used by Canonical itself and many other individuals and companies to manage the whole lifecycle of creating packages for Ubuntu and its distributions. Since quite some time also git is a supported VCS on Launchpad....
November 2, 2021How to Set a New Git Default Branch NameWhile GitHub’s default branch name for newly-created repositories is main since the end of October 2020, what about when you create a new git repository locally? first things first git made the default branch name configurable in version 2.28 and higher. So, when you run e.g. Ubuntu 20.04 like me, you may have an older version installed. Usually, you can’t install a newer version without updating the distribution. But there is hope, you can install a newer git version via a PPA (personal package archive):...
July 31, 2021How to Find Out Which Files Changed Most Often in a Git RepositoryI found this helpful command while cleaning up my Desktop - I cannot recall where I got it from :-/ git log --since 6.months.ago --numstat | awk '/^[0-9-]+/{ print $NF}' | sort | uniq -c | sort -nr | head This will list the top 10 most often changed files in your git repository. Why would you want to know this? Well, several things come to my mind: you get a quick overview what was changed in the last couple of months this could indicate problems such as a god class, when a file shows up you did not expect What do you think?...
May 12, 2021How to Create an Empty Git BranchWhat do I mean by an empty branch? Simply, a branch with no commits. Why on earth… Why would one even need an empty branch? There are not many reasons which come to my mind, but imagine you start a rewrite of an existing project, and you want to start from scratch, but you want to keep the rewrite in the same repository. For example tox does this: the current main version is on master the upcoming version 4, which is a complete rewrite, is on the rewrite branch....
April 27, 2021How to Globally Gitignore Configuration FilesUntil today, I did not make up my mind about what to do with configuration files, created by e.g. VS Code. Certainly, I do not want to commit them, but putting it into every’s repository .gitignore file is also cumbersome - and sometimes it is not possible. I always do a git add -u to avoid accidentally adding a venv or similar, so it did not really matter. Except… ❯ ....
January 11, 2021How to Install a Python Package Directly From a Git Branch From GitHubBernát Gábor is currently working on a complete rewrite for tox. I alpha-tested the latest release (4.0.0a2), and reported a couple of problems. Within a day Bernát published some fixes on the rewrite branch, and asked me to test it. That means there is no new package on PyPI, yet. So, I had to install tox directly from GitHub, to be exact, from the rewrite branch: pip install git+https://github.com/tox-dev/tox@rewrite or more general...