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 were simply told 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 childhood I taught arithmetic by representing playing cubes.
Therefore, I have prepared several drawings. You do not have to look at them in order 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 or index
- Local repository
- Server:
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.
Update Remote Repository
After preparing the 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 more commits in the
local repository that are ready for sharing by the rest of the world, they are sent to a
remote repository .
At this point, you can talk about the different states of the file in the development environment:
changed ,
intermediate (staged) and
fixed (commited).
Further you can explain:
- как показать изменения файла в рабочем каталоге:
git diff
- как показать изменения файла в промежуточной области:
git diff --staged
- как изменить файл в рабочем каталоге после добавления в промежуточную область
- и т. д.
Обновление среды разработки
Получение (fetching)
При выполнении
git fetch
данные из
удалённого репозитория перемещаются только в
локальный репозиторий.
Вытягивание (pulling)
При выполнении
git pull
данные из
удалённого репозитория перемещаются в две области:
- В локальный репозиторий:
fetch
- В рабочий каталог:
merge
Если важна история коммитов, рассмотрите возможность использования
git pull --rebase
. Тогда вместо команд
fetch + merge
выполняются команды
fetch + rebase
. Ваши локальные коммиты будут воспроизведены, так что вы не увидите в истории коммитов известную
форму бриллианта.
Дальнейшие действия
Можете добавить в среду разработки ещё одну область, чтобы проще прятать накопленные изменения:
грязный рабочий каталог.
Когда люди усвоят эти понятия, вам будет легче объяснить дальнейшее: ветви, историю коммитов, перебазировку и так далее, потому что прочный фундамент уже заложен.
Дружеское напоминание
Я работала с другими системами управления версиями (Visual SourceSafe, TFS и Subversion): по моему скромному опыту, недостаток знаний вредит и со старым инструментом, и с новым. Сосредоточьтесь не только на выборе инструмента, но и на его освоении.
Дальнейшее чтение
Полученные отзывы
Мой друг
Марк Виллаграса напомнил, что очень полезно решить
задачки Git и делиться с коллегами решением.
Ресурсы из
комментариев на Hacker News:
Прочитав
комментарии на Reddit, я подумала, что более точным названием этой статьи было бы
«Идея, как научить людей использовать Git», потому что это только идея, которая появилась в моей голове, когда я сама несколько лет назад изучала Git по
книге Pro Git. Статья не является полным руководством, лишь отправная точка. Уверена, что все эти ресурсы будут очень полезны. Спасибо!
И спасибо
Стюарту Максвеллу, который поделился ссылкой на Hacker News, и
u/cryptoz, который запостил её на Reddit!