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?

  • I forgot to checkout branch before making changes
  • Visual Studio 2013 git, only Master branch listed
  • What is the valid java regex pattern for git branch?
  • Should I merge master into a feature branch to bring it up to date? Would this be considered bad practice?
  • Weird git branch name
  • Checkout recently created branch
  • How do I commit only some files?
  • Recover deleted branch in Git
  • 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.