Checking in and out files within branches without moving to the Master Branch

Assume that I have 4 branches

Master Branch

Branch 1

Branch 2

Branch 3

I am currently in Branch 3 and I want to get all the files from Branch 2 to Branch 3 without committing the files to Master branch.
Is that possible?

  • Merging one change to multiple branches in Git
  • Gitflow - master and develop diverged
  • Git - multiple machines per developer - committing across machines but not to main branch
  • Why does git merge a branch into itself?
  • How does “merge without branch” work?
  • git — locking master branch for some users?
  • GitHub: Permission denied (publickey). fatal: Could not read from remote repository
  • GIT: How to see pulled/pushed changes in origin
  • Deploying only changed part of a website with git to ftp (svn2web for git)
  • IntelliJ IDEA Bitbucket Git integration not pushing
  • How do I enable cloning over SSH for a Gitlab runner?
  • GIT: Any way to commit on multiple repos?
  • 2 Solutions collect form web for “Checking in and out files within branches without moving to the Master Branch”

    • Option 1 – Merge branch2 into branch3

    It will record the merging history in your branch3.

    `git checkout <branch 3>
     git merge <branch 2>`
    • Option 2 – Fetch the files you want into branch3

      git checkout <branch 3>
      git checkout <branch> -- path/to/files

    You could either:

    • merge branch2 to branch3

       git checkout branch3
       git merge branch2
    • or, depending on what you need, force branch3 to become branch2

      git checkout branch2
      git branch -f branch3 branch2
      git checkout branch3

    (that would replace the history of branch3 by the one of branch2)

    In both cases, commits on master would be unchanged.

    Git Baby is a git and github fan, let's start git clone.