GIT: How to copy contents of one branch to other branch?

I have ‘develop’ and ‘InitialPomChanges’ branches. I want to copy all the contents of develop branch to InitialPomChanges branch.

  • Git rebase - force overwrite on merge conflict
  • IntelliJ IDEA - different team members on mac/PC
  • Create local git repository based on local repository based on github repository and keep it updated
  • Best fit for including or ignoring vQmod files in versioning
  • Git push not appearing in Github
  • How to setup a cloned Rails project on local machine?
  • How to upgrade to the latest version of Git on Windows? Still showing older version
  • Certificate problem while cloning a https url with git
  • Lost my schema.rb! Can it be regenerated?
  • Reference an image in BitBucket
  • return code 22, fatal: git-http-push-failed
  • Renaming a file in git
  • 3 Solutions collect form web for “GIT: How to copy contents of one branch to other branch?”

    You can use git merge or git rebase

    If you are on the InitialPomBranch, you can simply run

    git merge develop


    git rebase develop

    The first one will merge all the commits of the develop branch on to InitialPomBranch. The second one will put all the commits of the develop branch below the first commit of the InitialPomBranch

    Edit: Rebase will change the SHA hashes of all the commits of the InitialPomBranch. So you will have to run

    git push -f origin InitialPomBranches 

    to push all the changes

    Assuming you want to overwrite all the contents of InitialPomChanges with what is in develop (i.e. you want the contents of InitialPomChanges to exactly match develop), do the following:

    git checkout InitialPomChanges
    git checkout develop .  #copies the contents of develop into the working directory
    git commit -am "Making InitialPomChanges match develop"

    This will make the last commit in InitialPomChanges match the last commit in develop. To make future merges between the two branches easier, it would be a good idea to now do a git merge develop.

    Alternatively, if you want to change the contents of InitialPomChanges and do the merge in one single commit, you can do:

    git checkout InitialPomChanges
    git merge -s theirs develop
    $ git merge develop 

    Make sure that your current branch is InitialPomChanges

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