I have a feature branch, let's call it A, and a main line, let's call it B, where we deliver. The problem is the following:
Any idea how I could check out branch A in branch B? Remark: there are no changes in the main line since starting this feature branch A, so what I need is A in branch B. Thanks for any solutions in advance.
Would git fetch <remote> <remoteBranch>:<localBranch>
do this?
git fetch origin A:B
git push origin B
Solution: See the answer from VonC and also my questions about the index. Thanks for all responses.
cd /path/to/repo
git switch B
git restore -s A -SW -- .
git commit -m "override B with A content"
But I do not want to investigate file by file where an error might be in the content, I would just like to remove the state in B and get the state of A in B. How could I do that?
Keeping your history as is, you can restore A content on your current B
cd /path/to/repo
git switch B
git restore -s A -SW -- .
git commit -m "override B with A content"
pepe-botika69 adds in the comments:
If, after reverting, the
B
branch got new changes and you do not need them in your new commit (in this onegit commit -m "override B with A content"
), you should hard reset B to the point where you reverted A, and then apply the commands.