How to teach people to use git

Original author: Rachel M. Carmena
  • Transfer
  • Tutorial
I have to participate in different projects for work, so I know well how all my colleagues work. I remember that the company started using Git literally a couple of weeks before I arrived. On the monitors of the developers there were stickers hanging around: first add, then commit, then push.


They did not know why. Programmers simply said to strictly follow the instructions, otherwise the trouble. But problems arose so often that I decided to hold a Git seminar.

Idea


I like to make a map in my head. I do not say mental maps, because this is a well-known type of diagram. It's about some pictures, structures, or any graphical representation in the mind. For example, in my childhood I taught arithmetic by representing playing cubes.

Therefore, I have prepared several drawings. You don’t have to watch them to understand the text. For each there is an explanation.

In addition, it is very important to teach people terms. Otherwise, he will not understand the message from Git. Drawings are a good way.

Distributed Version Control System




In the figure, four areas are distributed as follows:

  • Development environment:
    • Working directory
    • Staging area or index
    • Local repository
  • Server:
    • Remote repository

Here you can explain the advantages of a distributed version control system.

Repository cloning




When cloning, data from a remote repository is moved into two areas:

  • Working directory
  • Local repository

Making changes to the working directory




There are two types of files in the working directory:

  • Monitored : Files that Git knows about.
  • Untracked : which have not yet been added, so Git does not know about them.

Upgrade remote repository




After preparing changes in the working directory, they must be added to the staging area.

When a number of changes have accumulated there with a common goal, it's time to create a commit in the local repository with a message about this goal.

If there are one or several commits in the local repository ready to be shared with the rest of the world, they are sent to a remote repository .

At this point, you can talk about the various states of the file in the development environment: changed , intermediate (staged) and fixed (commited).



Further you can explain:

  • How to show file changes in the working directory :git diff
  • How to show file changes in the staging area :git diff --staged
  • How to change the file in the working directory after adding to the staging area
  • etc.

Development Environment Update


Fetching




When executed, git fetchdata from the remote repository is moved only to the local repository .

Pulling




When executed, git pulldata from the remote repository is moved into two areas:

  • To local repository :fetch
  • To working directory :merge

If the commit history is important, consider using it git pull --rebase. Then instead of commands, commands fetch + mergeare executed fetch + rebase. Your local commits will be reproduced, so you will not see a known diamond shape in the history of commits .



Next steps


You can add another area to the development environment to make it easier to hide accumulated changes: a dirty working directory .

When people understand these concepts, it will be easier to explain further: branches, commit history, relocation, and so on, because a solid foundation has already been laid.

Friendly reminder


I worked with other version control systems (Visual SourceSafe, TFS and Subversion): in my humble experience, lack of knowledge harms both the old tool and the new one. Focus not only on choosing a tool, but also on its development.

Further reading



Received reviews


My friend Mark Villagrasa recalled that it is very useful to solve Git puzzles and share the solution with colleagues.

Resources from comments on Hacker News :


After reading the comments on Reddit , I thought that the more accurate title of this article would be “The idea of ​​how to teach people to use Git” , because this is only an idea that appeared in my head when I myself studied Git a few years ago using the Pro Git book . The article is not a complete guide, just a starting point. I am sure that all these resources will be very useful. Thank!

And thanks to Stuart Maxwell , who shared the link to Hacker News, and u / cryptoz , who posted it on Reddit!

Also popular now: