Git for beginners (part 2)

In the last article , I explained what Git is, how to install it and upload your code to GitHub. Today we will talk about teamwork on one project. And how it works in Git.





In this article, all work with Git will be through the command line.





Collaboration

Let's imagine that you and your friends have come up with a project with "blackjack" and ... You have shared responsibilities. Someone will do authorization and registration, while others will display news functionality. For this, branching comes in handy.





- 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
      
      



, .





Also, for ease of use in Visual Studio Code, I advise you to install this extension , which visualizes your branches and commits, and helps you work with them.





In the  Step by Step  telegram channel , I publish even more material for those who want to learn how to program and conduct educational streams, for everyone.








All Articles