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?

  • Move branch to another branch
  • Delete git master branch on a private server (not GitHub)
  • Remove large .pack file created by git
  • Maintaining multiple patches/feature branches for multiple development branches (and tags) in parallel
  • Git-tf checkin fails: commit has multiple parents. Using --deep option to create history in TFS
  • Bug fixes in a feature branch
  • git pull: There is no tracking information for the current branch
  • gitignore file but not folder
  • What are the supported git url formats?
  • last_rev is higher? with git svn rebase
  • Git rebase to stop, view and edit each on commit
  • Platform command not found for Jenkins for ios build?
  • 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.