git/

git: How to remove submodule pointer update in pull request

Case 1: it is done in a separate commit:

  • rebase on a base branch git rebase -i <base_branch>
  • in the editor, find the commit which updates the pointer and remove it from history (by replacing pick with d)
  • force push it when the rebase is done

Case 2: it is done in the commit which contains other changes

  • rebase on a base branch git rebase -i <base_branch>
  • in the editor, find the commit which includes the pointer update and mark it for editing (by replacing pick with e)
  • git will start rebasing the code and will stop on selected commit for editing
  • unstage the change git restore --staged <path_to_submodule>
  • continue the rebase git rebase --continue
  • force push it when the rebase is done
| 29 Mar 2023

git: Cherry-pick branch

Very useful command to cherry pick the whole branch

git cherry-pick 751a77^..8b62f1

^ - means the the first commit will be included too

| 3 Nov 2022

Use Github Desktop with pre-commit hooks with husky

If your repository has an installed pre-commit hook which uses husky or anything similar and you use Github Desktop for linux installed via flatpak it won’t work. The reason for this is that flatpak environment doesn’t have all necessary dependencies (npx, husky and etc.). There is a way to mount parts of your host file system to the flatpak environment (with --filesystem flag), but it excludes all sensitive folders (including /usr/bin/). A possible solution would be to mount the content of /usr/bin/ to a custom folder in flatpak environment and override PATH environmental variable. But the quick fix for now is to just disable it:

flatpak override --user --env=HUSKY=0 io.github.shiftey.Desktop
| 5 Sep 2022

Rebase git branch on a different branch

git rebase --onto new_base old_base
| 20 Dec 2021

Merge repositories and keep history

There is a special command git-subtree to merge / split repositories. It is not installed as a part of git package:

sudo dnf install git-subtree

The command to merge repository jsnjack/X to subfolder myfolder/new at branch master:

git subtree add -P myfolder/new [email protected]:jsnjack/X.git master
| 25 Nov 2021