Merging two identical codebases

Zach Weiler September 5, 2013

I'm test-driving a switch to git for our version control system (using SVN now), and having some issues managing a remote repository on Bitbucket. Two team members have the codebase for a project checked out, and we'd like to add the codebase to Bitbucket. We've both created git repos, but are unable to push to the same branch on Bitbucket. The only way to commit is to pull down from the remote repo first, which I'm hesitant to do (overwriting settings files etc.)

We also tried to push to two separate branches, and then merge, but it says the commits are unrelated and can't merge. I'm new to git, so I might be missing something obvious, but are there specific reasons I'm having such a hard time merging identical codebases in BitBucket?

1 answer

1 accepted

0 votes
Answer accepted
vimishor September 6, 2013

Before starting to apply what I wrote next, please make a backup. I don't know if I understood correctly what you need and something might break. That being said, lets give it a try.

Take the codebase from SVN and create a local git repository:

$ cd /path/to/src
$ git init

Start tracking the files:

$ git add

Make your first commit:

$ git commit -am "Initial import from SVN"

Add bitbucket as remote:

$ git remote add origin ssh://git@bitbucket.org/<username>/<repo>.git

And finally push everything:

$ git push -u origin --all

Then your second team member can pull existing codebase, make his changes in a separate branch, merge them back in the development branch and in the end push them to remote and send pull request if necessary. To make thing easier, you can use [gitflow](https://github.com/nvie/gitflow).

What I explained above regarding your colleague, can be done using gitflow like this:

# clone existing repo
$ git clone ssh://git@bitbucket.org/<username>/<repo>.git

# enable gitflow
$ git flow init

# start a new branch called "start my_super_feature"
$ git flow feature start my_super_feature

# make code changes, commit them, write awesome code

# when you are done, merge the branch where you worked in the development branch
$ git flow feature finish my_super_feature

At this point your colleague will have in the development branch your changes (from cloning) and his changes on top of yours. Now he can push the changes back to origin.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events