Search code examples
gitversion-controlcommitcollaboration

How do I make changes to the repository at the same time as someone else?


I'm pretty new to Git. Right now I only have a master branch for a repository. I'm starting to collaborate with another individual and I'm very confused as to how I can make adjustments at the same time as this person. I'm using Tower so I don't really need to learn anything on the command line -- I'm really just looking for a process description.

My instinct is to each have our own branches that we're separately working on. Is this the right approach? Do we just merge these branches with our master once the work is completed?

Let's say this other person makes a change and commits it to the master branch while I've been working on something else in my branch -- how do I merge his work with my own?


Solution

  • If you both work on the same branch, and he pushes his changes, you won't be able to push your changes. But what you can do is to pull the changes into your local copy, which will merge your and his changes. If there are some conflicts, you will have to resolve them manually. You can then push the result of that merge, which will contain both sets of changes.

    In general, it probably doesn't make sense to have one branch for you and one for him. What makes sense is to create “feature branches”. If you are working on feature A, create a branch for it. When you're done, merge it back to master. This allows you for example to make emergency bugfixes to master even while your feature is unfinished.