7

I'm working half time at home, half time at the office. Each task must be done into a dedicated, separated, branch, merged after peer review.

Our project is backed by Bitbucket, we use Jira and Jenkins too.

I use only one remote repository and two local repositories.

I have a recurrent problem: some conflicts occurs between me (@home) and me (@agency)...

here is my process:

Monday, at the office, in a branch named "JamesBond007" derived from master :

git add --all
git commit [--amend]
git push [-f] origin remote/JamesBond007

Tuesday, at home:

git checkout master
git pull
git checkout JamesBond007
git pull --rebase origin master

Wednesday, at the office:

git checkout master
git pull
git checkout JamesBond007
git pull --rebase origin master   **<-- conflict: git mergetool command needed!!!**

My workaround:

rm -fr repo
git clone ssh:repos-url

Where is my mistakes, how can I push/pull code from two local repos to/from the server without conflict?

Aubin
  • 14,617
  • 9
  • 61
  • 84

2 Answers2

5

I have a very similar setup and never have merge conflicts: I essentially do what you do, but I never use rebase in any fashion, until possibly at the very end, as part of merging to master.

Concretely:

  • I commit and push frequently while I'm working, using the origin as a backup tool.
  • I can switch easily to another computer by just doing a default fast-forward pull/fetch on it, and then getting to work there.
  • Finally, when the code has been reviewed in the PR, I perform some kind of merge or rebase or squash/merge depending on the project's style.

I know that this is not the preferred "expert" way to work, but it has two awesome benefits:

  1. I switch between multiple development computers (desktop here, laptop or two there...) without any thought at all. Just a git pull and I'm off...
  2. I never have conflicts.
Dogweather
  • 15,512
  • 17
  • 62
  • 81
0

The problem happens when you rebase the working branch to master in multiple places.

Each task must be done into a dedicated, separated, branch, merged after peer review.

There are multiple ways to make it work (depending on your familiarity with git). Based on this I'm assuming you have to rebase the commit logs.

I'm going to suggest a simple change to your workflow: At the end of everyday, always push to origin and delete your local branch.

# Assuming you're on JamesBond007 local branch
git push [-f] origin remote/JamesBond007
git checkout master
git branch -d JamesBond007

This way, you'll be certain that you pushed everything that's deleted locally. Next time you come back to the same computer, you won't suffer from the problem that you have a local branch that has a different base commit.

miaout17
  • 4,715
  • 2
  • 26
  • 32