Difference between #3 and #2 of Collaborative software with git

unchanged
Title
Collaborative software with git
unchanged
Category
Tutorials
unchanged
Tags
git, github, collaborative software, pull
changed
Content
Git basics ...
--------------

The most difficult thing in a big project, is to manage conflicts
with files modified by others users. Git can do this work for us.

I can create a project on my local computer

$    $ git init

I can add files to it

$    $ git add .
$
    $ git commit -m 'A little story to understand changement'

I can create a repository on github (or bitbucket).
I can add this remote repository to my own local project:

$    $ git remote add origin
git@github.com/<yourusername>/<yourrepository>.git

And then I can push my commitedcommitted files to
the remote repo.repository.

$    $ git push origin master

Collaborative software
----------------------

But what if we work with others developer? What if we make changes
into the same files?file? I'll give
an answer to this question.

### Better case: no conflicts

In better cases, there are no conflicts. This means that a developer can change
the view. Another one the model. Both concan run the
sequence:

$    $ git add .
$
    $ git commit -m 'committed some stuff'
$
    $ git push origin master

### Worst case: conflicts

There are different ways to solve conflicts in git. I'll explain two.

#### Manage versioning of our software

Imagine to have your new project:

$    $ git init
$
    $ touch readme
$
    $ git add .
$
    $ git commit -m 'first commit'

Now, if you want, you can see the graph of your project:

$    $ git log --graph --oneline

The output will be like this:

*    * 719b3f2 first commit

This is your version 0.0. You can create a branch 0.0.

$    $ git checkout -b 0.0

So you'll have a branch in all life of this project. But what if you want
to add some features for version 0.1? You can call this new feature like
'add an index file' and 'add a changelog file'.
Point to 0.0 version and create a branch. Add some files. Commit. ... follow
these steps:

$    $ git checkout 0.0
$
    $ git checkout -b 0.1.index 
$
    $ touch index.php
$
    $ git add .
$
    $ git commit -m 'Added index file'

Take a look again to the graph of your poroject:project:

*    * 21cb1bc Added index file
*
    * 719b3f2 first commit

Come on!!! =) We can add new feature before release 0.1 version!

$    $ git checkout 0.0
$
    $ git checkout -b 0.1.changelog
$
    $ touch changelog.md
$
    $ git add .
$
    $ git commit -m 'Added changelog'

Again to the graph

*    * e9fe3ad Added changelog
*
    * 719b3f2 first commit

We have two steps because with "$ git checkout master" we have
startstarted this branch from 0.0.

Now we have 0.0, 0.1.changelog and 0.1.index branch. What you need, now, is
create your version 0.1:

$    $ git checkout master
$
    $ git checkout -b 0.1
$
    $ git merge 0.1.index
$
    $ git merge 0.1.changelog

And now? 

$    $ git log --graph --oneline

*    *   3dbd397 Merge branch '0.1.changelog'
|\  
|
    |\  
    | * e9fe3ad Added changelog
*
    * | 21cb1bc Added index file
|/  
*
    |/  
    * 719b3f2 first commit

Now we can see our two branch.

#### Manage conflicts with other developers

IsIt's very dangerous to manage conflicts
inon merge with others
developer.developers. I suggest to use a good practice.
The first timeFirst you can clone your project. Then you
can commit inon your local master. But ... what you can do
to update your version to the remote
versione?version?

$    $ git pull origin master

Pull execute 2 command. The first is "git fetch" that update your
code. And the second one is "git merge". So,
youyour code is merged with the one the is online. Now you
can push your code to remote repository stored on github.

$    $ git push origin master