Monday, February 20, 2017

All about version controlling tools - GitHub / bitbucket Part - 3

2. Multiple users working on the same branch.

If two or more users are using the same repository to push code into, there will be conflicts. In order to resolve the issues checkout the steps below.

Let's take an example. Suppose that you already have a codebase in GitHub

|-- master
|-- dev(default)
    |-- feature/myfeature *

In the team what if 2 users are working on the same feature. So that they'll have to use the same branch(Not a good practice though). Let's take our 2 users as USER1 and USER2. Suppose that the USER1 and USER2 have already cloned the repo into the local machine.
git clone <ulr here>
Now both the users are working on the project. They have to stick with few guidelines in order to prevent from conflicts. 

1. Whenever they have completed something, commit locally but do not push to the feature/myfeature branch.

2. When ever they want to push the code to the branch follow the steps given below.
  1. git add --all
  2. git commit -m "your changes"
  3. git pull
  4. After pulling, there can be conflicts in the local code. You have to correct them manually and then 
  5. git commit -m "new changes" 
  6. and finally
  7. git push -u origifeature/myfeature
  8. if you get an error message, then repeat steps 3 to 7 again.

3. What is the difference between 'git pull' and 'git fetch'?

git pull is what you would do to bring a local branch up-to-date with its remote version, while also updating your other remote-tracking branches. In the simplest terms, git pull does a git fetch followed by a git merge.




No comments:

Post a Comment