Search code examples
pythongitgitpython

Gitpython merge replacing the code in master from the merged branch


I am trying to merge two branches using gitpython.To test it out I have a kept a single file main.py with different code in two branches master and release.Finally I am merging the release branch onto master.After the merge operation the code in master branch is just getting replaced with the code in release branch.

main.py(Master)

import os

main.py(Release)

import git

Merge.py(Code-snippet)

repo = git.Repo.clone_from(HTTPS_REMOTE_URL, DEST_NAME)
repo.git.checkout('release')
repo.git.checkout('master')
repo.git.merge('release')

main.py(Master - Expected)

import os
import git

main.py(Master - Actual)

import git

Solution

  • There was an another issue due to which the merge was not working.The above code works fine to merge one branch onto another.