1

I have a situation like this:

  1. I have a main branch master, a feature branch feat and a fixup branch fixes.
  2. The fixes branch hardcodes some assumptions that make it possible to do local development. (Things like not requiring https or licenses or hardware keys. Stuff that I don't want to accidentally push to prod)
  3. I want to stay on fixes branch locally but I want to make commits on the feat branch.
  4. I want the fixes branch to always be on top of feat.

Assume that this is my current situation:

A---B---C <---master
         \
          D---E---F <---feat
                   \
                    G---H <---fixes, HEAD

I do some work and make a commit. This is what I want the result to be:

A---B---C <---master
         \
          D---E---F---I <---feat
                       \
                        G---H <---fixes, HEAD

My idea says that it can be done by first making commit I on fixes then cherry-picking it on feat then resetting fixes to H then rebasing fixes on top of feat.

This seems like a lot of work to do manually. Is there a way to automate this?

Kushagra Gupta
  • 514
  • 2
  • 13
  • That operation is carried out like this: `git checkout fixes; git rebase feat`. It could also be carried out with `git rebase feat fixes` – eftshift0 Dec 16 '22 at 11:24
  • However, if this is a permanent setup in which you'll forever rebase this branch without ever merging it into something, it's a suboptimal way of dealing with local config. Take a look at `.gitignore` first, and if these files are versioned (and should stay so) there are solutions, like the `--skip-worktree` option of `git update-index`. Don't jump on it immediately though, first be sure it suits your needs. – Romain Valeri Dec 16 '22 at 11:26

1 Answers1

1

I want to stay on fixes branch locally but I want to make commits on the feat branch.

An alternative approach would be to use git worktree, in order to have a separate folder set on feat.
You can create I and push it from that folder.

Back to your regular Git repository working tree, checked out on fixes, you can git rebase feat fixes.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250