Merging two identical codebases

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

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 Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

631 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot