How to share a git branch (or theme) with multiple developers

I am following the document flow described below since I have found many links pointing to this page as a good workflow. As mentioned in the article, the “function” branches are shared between developers, but do not go to the central repository.

Let's say developer "A" launches a new function branch with git checkout -b newfeature develop . Now let me say that developer “B” should also work on this feature. It is my problem.

What I've done:

  • developer "B" adds developer machine A as a remote
  • developer "B" launches git branch remoteA/newfeature
  • developer "B" works in this branch, exits and returns the changes back to remoteA.

Step 3 is not working right now. I get a message:

remote: error: by default, updating the current branch in a non-smooth repository is denied, because it will create an index and the working tree does not match what you clicked, and will require 'git reset --hard' to match the HEAD work tree.

remote: error: you can set the "receive.denyCurrentBranch" configuration of the variable to "ignore" or "warn" in the remote repository to allow clicking on the current branch; however, this is not recommended if you have not agreed to update your work tree in accordance with what you clicked in some other way.

remote: error: To cancel this message and keep the default behavior, set the receive.denyCurrentBranch configuration variable to 'Fail'.

I already set sharedRepository = true , but that didn't help.

I have 2 questions:

  • What is the correct way to share feature branches between developers?
  • How can I discard changes in developer repository to developer source?
+7
source share
2 answers

You can click on a non-bare repo. What you cannot do is click on a non-bare repo in which there is a branch that you click to check. The reason for this should make sense. Changing files someone else is working on would be wrong.

Usually you need to click a wizard or other common shared thread. To avoid this conflict, the owner of the remote non-bare repo should work on the local branch, or at least on some other branch. Then you can click on the shared branch.

To use your example:

  • developer "B" adds developer machine A as a remote
  • developer "B" launches git branch remoteA/newfeature
    • Developer "A" works in the local branch. git checkout -b work-newfeature
  • developer "B" works in this branch, exits and returns the changes back to remoteA.
    • Developer "A" reinstalls new job: git rebase newfeature
+5
source

The easiest way to split function branches is to simply push them into the central repository so that everyone can pull them out. That way, you can simply use the infrastructure that you already have for the main repository, and you can easily exchange code.

Once the function branch on the remote control is no longer needed, you can simply delete it by doing

 git push <server> :branch 

I would advise against sharing directly between the development machines, as this is due to problems, such as users on different networks (not connected to each other).

If possible, you can also use the GitHub model, which has one central repository on the server (blessed main repo). In addition to this main repository, each developer has a “fork” of this repository, where he has full access to the commit and can push branches to his liking.

In this case, you can add colleagues' forks as remotes to your repository, while maintaining easy access to one centralized server (while maintaining problems with setting SSH keys on each machine, etc.).

A description of the GitHub model can be found here: http://www.eqqon.com/index.php/Collaborative_Github_Workflow

Update . As the commentator noted, this is a good link to get started with a workflow with centralized functionality: http://nvie.com/posts/a-successful-git-branching-model/

Update 2 . To expand your second question:

What you are trying to do is click on the non-bare repository of another developer. Git, introduced in some previous version (I think about 1.6), the concept of a bare repository is a repository that does not have a registered state, but contains only a database, which usually goes into .git .

The rationale for this change was that whenever you click on the repository of your fellow colleagues (who is currently working on something), you manipulate the repository right under his nose. Therefore, it checks the version of featureA-1 .. starts to work. Then you click featureA-2 on your repo, and when he wants to commit, he runs into problems because the branch he was in is being promoted by one message that he did not see during development.

Because it is quite destructive. Most people have adopted the concept of local git repositories (the ones you are active in) should be private, while you have the publicly available git-repo (fork) where you receive and share changes. This way you will never be interrupted by anyone else during your work (which is generally the idea of ​​a decentralized model) and can only include the changes you want to have. (No one can direct something to your current job).

+7
source

All Articles