Git has the concept of hooks: bash scripts that are invoked at certain points in the Git lifecycle. One handy use is a pre-push hook that runs Rubocop. It...

...will prevent pushing code that Rubocop finds fault with. Configuring the hook Git hooks are normally stored locally with a repository. They are not committed. Store this snippet in .git/hooks/pre-push...

Sometimes I ran across a GitHub merge request of a gem where it was not completely obvious in which version the change was released. This might be the case for...

...a bugfix PR that you want to add to your project. Git can help you to find the next git tag that was set in the branch. This usually has...

Using git fixup helps you to speed up appending changes further back in the git history of your feature branch. Example: git commit --fixup aabbcc # Create a commit with the...

...message "fixup! Commit message of aabbcc" git rebase -i --autosquash master It would be nice if you could use this feature without the -i flag, but until now it seems...

makandra dev

...me or my peer reviewer is able to parse 500k+ lines of code. Fortunately, git has some handy diff options ready: option comment --color-moved=dimmed_zebra Highlight only changes...

To tackle the rename limit mentioned above, update the local or global git configuration. git config diff.renameLimit 9999 Furthermore, I encourage you to further split the diff into...

If you are using git submodules in Gitlab CI, you might run into a "The project you were looking for could not be found or you don't have permission...

Gitlab added a feature that new projects are no longer allowed to be cloned inside CI runs of other repositories by default. To fix this

Just like Ruby Gems tag their version releases to the corresponding Git commit, it can be helpful to track production deploys within the commit history. This task does the tagging...

... desc 'Tag the deployed revision' task :tag_revision do date = Date.today.to_s puts `git tag deploy-#{date} #{fetch :current_revision}` puts `git push --tags origin` end end # config/deploy/production.rb

...rebase one clean commit interactively onto main without going through each commit individually using git rebase -i main. What it does: Opens an interactive rebase UI to choose squash/edit/fixup for...

...you squash, reorder, edit, or drop commits. Info This is not the same as git rebase -i main, which would rebase your branch onto main, changing its base. Example:

Sometimes you might need to nest a git-project inside another git-project. The right strategy is to use submodules in this case. How git submodules work Each submodule is...

...a own git repository Once you commit changes in a submodule, the parent repository can link the new sha as its reference You need to take care manually that your...

Geordi provides a pretty neat way to generate beautiful commit messages according to your stories in Linear: geordi commit

...Aug 11 09:42:34 2023 +0200 Add Apples as a new fruit diff --git a/app/models/apple.rb b/app/models/apple.rb new file mode 100644 index 0000000..a51cbad --- /dev/null +++ b/app/models/apple.rb...

+ + attr_accessor :type + + def to_s + I18n.t(type, scope: 'fruits.apples') + end +end diff --git a/spec/models/apple_spec.rb b/spec/models/apple_spec.rb new file mode 100644 index 0000000..6b9a90e --- /dev/null +++ b/spec/models/apple_spec.rb...

Inspired by recent "git shortcut" cards I figured it would be nice to have one of these for rebasing a few commits onto another branch. The usual notation is prone...

...You may add this rebase-onto function to your ~/.bashrc: function rebase-onto { commit=$(git log --oneline | fzf --prompt 'Select the first commit you want to move' | awk '{print...

worktrunk.dev

Worktrunk is a CLI tool that manages git worktrees for you. This can be useful when you want to work on multiple instances of the same repository with separate AI...

makandracards.com

In order to have more human readable git branches, do git pull --rebase To always pull like this, write these lines to your ~/.gitconfig: [pull] rebase = true

git config --global pull.rebase true Note that this will break if you pull from other upstream branches like git pull origin other-branch If you keep rebasing by default...

Git allows you to set push options when pushing a branch to the remote. You can use this to build an alias that automatically pushes a branch and creates a...

...alias] section: mr = push origin HEAD -o merge_request.create -o merge_request.draft Now you can do git mr and a draft merge request will be created. Target branch is your project's...

github.com

The linked GitHub repository is a bit like our "dev" cards deck, but groomed from a single person (Josh Branchaud). It includes an extensive list of over 900 TILs on...

...many topics that might be interesting for most of us. (e.g. Ruby, Rails, Git, Unix..) Ruby Here is an excerpt of all the Ruby TILs that were new to me...

Git commands like diff use the less binary for their output representation. I often find myself searching for strings like todo, then switching to the case-insensitive mode (-i) and...

...re-doing my search. Today I figured out that you can configure git to show case insensitive diffs every time: git config --global core.pager 'less -i...

stackoverflow.com

...changing this, so think before you do it. If you do, you can tell git to stash automatically before pulling: git config --global rebase.autoStash true Now on pull, git will...

...Note that applying your changes may lead to unresolvable conflicts! Further see a common git config with this configuration enabled...

makandra dev

Saying git diff only shows unstaged changes relative to the index (or HEAD if the index is empty, alternatively any hash or branch you supplied) but leaves out files you...

...already staged for the next commit. To diff your added changes with HEAD, say: git diff --cached Effectively, this gives you the changes you will commit when you run git...

Why Rails has multiple schema formats When you run migrations, Rails will write your current database schema into db/schema.rb. This...

...as the last release is not yet on rubygems.org. # Gemfile gem 'puppet-ghostbuster', git: 'https://github.com/voxpupuli/puppet-ghostbuster.git', ref: 'XXXXX' After that you can use puppet-lint to find dead code...

...in your project: # You probably need to set some ENV Variables, see https://github.com/voxpupuli/puppet-ghostbuster#environment-variables export HIERA_YAML_PATH="/home/bob/code/puppet/hiera.yaml" export PUPPETDB_URL="http://localhost:9000" find . -type f -exec...

Sure, you have a project directory – but all of it is tracked by Git. A project's tmp/ directory is usually not tracked, but by definition it is not...

...a related-files/ directory within your project(s). To keep this directory untracked by Git in all your projects, add it to your global .gitignore file with echo related-files...

If you want to see the git history of a project file, that doesn't exist anymore, the normal git log won't work. You have to add certain flags...

...to make it work: git log --all --full-history...

dev.to

...you may add an alias such as this to your ~/.bashrc: alias recent-branch="git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/ | fzf | sed 's/\* //g' | xargs -I...

...git checkout {}" alias rb=recent-branch Now whenever you want to switch back and forth between your most recent branches, type recent-branch, select one and press enter...

...and fix trailing whitespace in your commits. Bypass # it with the --no-verify option to git-commit. # detect platform platform="win" uname_result=`uname` if [[ "$uname_result" == "Linux" ]]; then

...Removed trailing whitespace in \033[31m$file\033[0m:$line_number" done echo # credits: # https://github.com/philz/snippets/blob/master/pre-commit-remove-trailing-whitespace.sh # https://github.com/imoldman/config/blob/master/pre-commit.git.sh # If there still are whitespace errors, print the offending file...