1

I am currently using git for a project that has two participants (me and my friend). SO I did the following :

I created a repository on a machine that is always accessible by any machine on our local network.

We both cloned this repository into our respective local machines creating local repositories.

Now suppose at one point of time (wherein all three repository copies are in the exact same stage), I fork a branch and start some development in that branch. I push those changes to the remote and I see that a new branch has automatically been created in the remote.

On the other machine I pull that branch into a new local branch of the same name so they are all in the same state again.

Now when I am done with this fork branch, and I want it merged with the master, I simply did a checkout to master and did a git merge my_branch. Now how do I make this change reflect in the global repository and the other local repository ? Will I have to issue merge commands there too ? Or is there some way to push and pull so that merges are automatically synced?

What IS the git philosophy ? Should all local repositories and the global repository be exactly in sync commit by commit so that the trees everywhere are exactly same ? Or can individual trees be different and whatever branches are needed be pulled from the remote accordingly ?

(I have learned GIT by searching commands for whatever I need done, however I am very confused by how it is supposed to work)

The remote repository I created was a bare repository

AnkurVj
  • 7,958
  • 10
  • 43
  • 55

5 Answers5

5

After you've merged into master, use git push to push that merge up to your origin repository, just like you would with any other commit. Your friend will need to git pull to get your changes, but so long as there's nothing new in the origin, and your friend hasn't done any changes in master in their own copy, no additional merges will have to be run.

The repositories won't always be exactly in sync; that's one of the key differentiators of a distributed VCS.

Gareth
  • 133,157
  • 36
  • 148
  • 157
jbowes
  • 4,062
  • 22
  • 38
  • 2
    Note that a centralised workflow like this relies on the central repository being a bare repository. You can't (shouldn't) push into a repository with a working directory – Gareth Feb 17 '12 at 12:06
  • @Gareth The remote repository I created was a bare repository – AnkurVj Feb 17 '12 at 12:08
  • @AnkurVj then you'll be fine :) But of course it's a useful note for anyone else who stumbles across this question – Gareth Feb 17 '12 at 12:08
  • So, if I merge two branches on my local repository and then push the branch to the remote repository, will the remote repository's branches get merged ? – AnkurVj Feb 17 '12 at 13:53
1

This is basically the situation at my office as well (a git repo on each developer's computer, and one on the company network.

You don't need to re-merge your changes remotely after you've merged them into your master. Firstly, you need to make sure that the central repo was created with

git --bare init

Then, when anyone wants to merge changes into the main repo, they do a git pull (to get any changes that have happened to it since their last commit; this is where you may need to do some merging on your end) followed by a git push (after resolving conflicts, obviously). The result is a newly merged commit on the "central" server.

I don't know if this is The Git Way, but it's worked for us so far.

Inaimathi
  • 13,853
  • 9
  • 49
  • 93
1

(I have learned GIT by searching commands for whatever I need done, however I am very confused by how it is supposed to work)

I would highly, highly recommend you take the time to at least browse through the progit.org book. It's got a wealth of information and some nice graphics to explain the concepts of branching and commits.

Or is there some way to push and pull so that merges are automatically synced?

If you want to automatically push from one of your local branches to a remote branch, there are tools that would help (git post hooks, for example). However, I'd be confident in saying that this is not a solution that fits everybody's needs - here's a link to a related question which you may find useful.

EDIT:

What IS the git philosophy ? Should all local repositories and the global repository be exactly in sync commit by commit so that the trees everywhere are exactly same ? Or can individual trees be different and whatever branches are needed be pulled from the remote accordingly ?

Git is not a server-client SCM, it's a distributed revision control system - treating git the same as you would, say, CVS or SVN isn't always the right approach. A workflow that is rather popular at SO is found here - there are quite a few related questions you might find useful as you develop your own workflow. (1) (2)

Community
  • 1
  • 1
simont
  • 68,704
  • 18
  • 117
  • 136
0

Now how do I make this change reflect in the global repository and the other local repository ? Will I have to issue merge commands there too ? Or is there some way to push and pull so that merges are automatically synced?

There is a git push command.

penartur
  • 9,792
  • 5
  • 39
  • 50
0

After merging you need to push your changes. Do git push

gsagrawal
  • 2,900
  • 4
  • 27
  • 27