Switch which branch a branch is a branch of in git -


i'm working in multi-developer environment on repository has branch called "develop", updated frequently. however, there's few issues develop, , i'd create branch on local machine, "custom_develop", can make couple of commits don't intend push main repository.

when work on feature branch, i'd start off creating branch of custom_develop called "feature/ticket-123", , create couple of commits. then, when think i've finished work on ticket 123, want make "feature/ticket-123" become branch of "develop" rather branch of "custom_develop", can create pull request merge develop on remote server.

how can in git?

if try doing

git checkout develop  git checkout -b custom_develop  git commit -m "commit don't want share"  git checkout -b feature/ticket-123  git commit -m "ticket-123: refactor"  git rebase develop 

i get

current branch feature/ticket-123 date. 

and git log still includes "commit don't want share" commit.

i use diagram describe question visually.

this have:

a <- develop  \-- b (don't share) <- custom_develop       \--c <- feature/ticket-123 

this want:

a <- develop  \-- c' <- feature/ticket-123   \-- b (don't share) <- custom_develop            \--c <- no branch 

the problem default rebase try replay commits have occurred merge-base of current commit , commit rebasing onto. in case merge-base (last common parent) a. therefore, there nothing replay, there no commits have diverged on develop branch. why getting "up date" message. however, if develop had progressed, still have problem because git replay of commits onto wherever develop including commit b, want ignore.

therefore, have use --onto option of rebase:

git rebase --onto develop b 

this replay commits in current branch not parents of b (or b itself) "onto" develop.

the syntax can confusing. in default case specify "onto" commit, without --onto keyword. in non-default case specifying "ignore" commit need specify --onto keyword though adding "ignored" commit. better if git allowed specify git rebase develop --ignore b.

another option, required if commits wish ignore not @ bottom of branch i.e., commits following merge-base, use interactive rebase.

git rebase -i develop. 

then, when interactive window shows comment out commits wish ignore.

lastly, not such idea have permanent custom branch. better put environment specific properties in file ignored using .gitignore.


Comments