Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Git/Github properly when working on a team

Tags:

git

github

Example:

  • I cloned the Github repository, created a new branch and started working on a feature.

  • My co-worker clones the same exact Github repository, creates his own branch on his local machine (git checkout -b mylocalbranch), and works on his own feature.

  • My co-worker finishes his feature before I do and pushes it to production and back to Github.

  • I finish my feature 30 minutes later and want to push my work without causing any conflicts.

What is the best way to push my work to production and back to Github without causing any conflicts?

like image 834
Smooth Avatar asked Dec 19 '12 19:12

Smooth


People also ask

What is GitHub and how does it benefit your team?

GitHub is a for-profit company that offers a cloud-based Git repository hosting service. Essentially, it makes it a lot easier for individuals and teams to use Git for version control and collaboration. GitHub's interface is user-friendly enough so even novice coders can take advantage of Git.


2 Answers

Lets say your co-worker merged his code to production branch.

Now the branch yourfeature you created from earlier production is outdated a bit and has few commits by you on top of it.

What you have to do now is :

  • switch to production branch
  • Pull it (so you have latest changes including changes by ur co-worker)
  • go to your yourfeature branch
  • Rebase your branch with production : This will replay your commits of this branch over the latest production.
  • If any conflicts arise: They are due to the same line changes made by your co-worker where you are also updating something.

Read more on rebasing here

like image 68
Rahul garg Avatar answered Nov 16 '22 22:11

Rahul garg


Well, you could checkout the branch you wish to merge into,

git checkout master

then merge your code

git merge [current_branch]

There is always the possibility of conflicts and in that case you simply have to deal with them and resolve them.

This article should help: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging

like image 33
Foggzie Avatar answered Nov 17 '22 00:11

Foggzie