No último artigo , expliquei o que é Git, como instalá-lo e fazer upload de seu código para GitHub. Hoje vamos falar sobre o trabalho em equipe em um projeto. E como funciona no Git.
Neste artigo, todo o trabalho com o Git será por meio da linha de comando.
Colaboração
Vamos imaginar que você e seus amigos criaram um projeto de "blackjack" e ... Vocês dividiram responsabilidades. Alguém fará autorização e registro, enquanto outros exibirão funcionalidades de notícias. Para isso, a ramificação é útil.
- commit (), . , master
( main
) . , master
- .
- () . , , master
.
? commit master
. .
, :
git branch <_>
#
git checkout -b <_>
, . .
, . , . , - , ID , , . :
3424_fix_catalog_ajax
commit .
:
git checkout <_>
, , master
. master
:
# master
git checkout master
#
git pull origin master
# merge ,
# master
git merge <_>
❗️ merge
, master
, .
merge
( bugFix
) master
.
, , commit, :
git status
, . , master
, GitHub. master
:
git checkout master
# GitHub
git push origin master
, master
GitHub. , :
git checkout <_> git push origin <_>
?. , . , . , GitHub.
?
GitHub . GitHub. , .
, "" :
git clone <_>
? GitHub , Code
, . .
, , master
. :
# master
git checkout master
# GitHub
git pull origin master
, master
.
, , , :
git pull
.
?
Git , . . , . , . , . , - :
#
git checkout new_styles
git merge master
#
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.
<html>
<head>
<<<<<<< HEAD
<link type="text/css" rel="stylesheet" media="all" href="style.css" />
=======
<!-- , - -->
>>>>>>> master
</head>
<body>
<h1>Hello,World!</h1>
</body>
</html>
(HEAD) - , , . ( ====
>>>>master
) - , ( master
). , , :
<html>
<head>
<link type="text/css" rel="stylesheet" media="all" href="style.css" />
</head>
<body>
<h1>Hello,World!</h1>
</body>
</html>
git add <_>
commit:
git add index.html
git commit -m "Merged master fixed conflict."
:
git diff <_> <_>
:
git branch -d <_>
:
git log
:
#
git help
#
git help <_>
# clone
git help clone
Além disso, para facilitar o uso no Visual Studio Code, aconselho você a instalar esta extensão , que visualiza seus branches e commits e ajuda você a trabalhar com eles.
No canal de telegramas Passo a Passo , publico ainda mais material para quem quer aprender a programar e a conduzir roteiros educacionais, para todos.