How to make Git as safe as possible for beginners?

I am currently working on a course module for scientists, git programming, and version control. One of the benefits I'm trying to convey (among others) is that using VC can protect you from losing your job. But of course, as you know, Git gives you ample opportunity to shoot in the foot. It would be a shame if students in the course lost their jobs due to the use of a system that was supposed to prevent this in the first place :-)

My question is: would you have any tips on things you could teach people (teams, workflows, tricks) that fix them due to issues when using Git ?

In particular, this mainly applies to people with a solo workflow, without previous Git experience and, possibly, entry-level programmers.

Examples of tips I know of:

  • Regularly click your code on something like GitHub or BitBucket. Also make backups :)

  • Stay away from commands like git rebase until you know what you're doing.

  • Make a backup of your code directory (including .git dir) before playing with rewriting the story, especially when you're still learning.

Thanks!

+7
git
source share
6 answers

I think you are doing something more complex than necessary.

To restore the previous state, regular fixing of the local repo is required. At this point, you do not need to introduce branching or merging. Perhaps flagging as a way to revert to specific versions.

To reduce the risk of code loss due to a lost computer / crash backup on your hard drive, this is good advice. But this is the same for everything, not just code.

If you want to introduce code sharing, clicking on github or bitbucket is an option. While you are only pushing, and you are the only one who pushed him, it is very simple.

+3
source share

The most common rule would be: make sure you know what the team is doing before using it.

It may be rejected by more specific advice:

  • More generally, avoiding git rebase , we could refuse to change history.
  • Avoid using the -f flag in comments ( push , clean , ...)

Having a safety net before doing something potentially dangerous is always really a good idea. However, there is no need to copy the entire directory: just put the tag on your original latch to be able to checkout if everything goes wrong, enough and less cumbersome.

+1
source share

As @nullability says, the question of when and how often to commit is really important. If you are going to make monolithic changes that are installed every week, you are actually losing data because

  • you cannot go back to the specific intermediate steps you took to get the current set of changes / solutions.

  • each fixation is a chance to explain to your future self in a few words why you decided to make a certain set of changes. (And, in my experience, you are much more likely to spend time creating a meaningful commit message if the set of changes is autonomous and does not require you to write a few paragraphs of text to explain everything.)

Getting people to view git (or any decent DVCS, really) as a tool that can actually help manage the encoding process - instead of the necessary evil - is key here. (To control this point, you might want to show your students git bisect .)


A few things to check when deciding whether a given set of changes are ready to be ready:

  • Can you summarize the changes in one sentence?
  • Is the code compiled?
  • Do the tests pass?
+1
source share

The main source of loss for beginners, I think, will not be able to correctly add and fix content. Therefore, you must teach them how to verify that their work has been completed. For example, explain the git commit message:

nothing added to commit, but no traces of files (use "git add" to track)

And show them how to use the git status command, and read its output, and emphasize that they need to make sure that there are no unsaved changes after the commit.

Another potential source of data loss is errors when trying to do fancy things. Probable errors are small typos, forgetting flags and completing the steps of a multi-step task out of order. Therefore, if you taught a programming course and you needed to teach minimal version control, I would say that he should teach only tasks with minimum steps and a minimum of flags:

The main solo workflow, which uses only commit to save work, and revert to roll back offers has virtually no room for errors that lose data. A solo user can probably get away from using only commands, but still gets a fair value due to source control.

 git commit -a git revert git status git diff git log 

However, since the module is about version control, you probably need to cover more than just a bare minimum. In this case, when considering advanced tasks, you should discuss probable errors in each team (that is, indicate specific possibilities in which probable errors, which I mentioned above, lead to data loss), discuss specific warnings and error messages. Also include a variety of exercises that intentionally destroy data so students can see what they like.

You can also use internal git elements so that students have a proper mental model of how data is stored in git repositories and show some advanced cases of data recovery ( for example ).


Pointing out that version control is not backup (and backups are not version control) seems reasonable.

I would not say avoiding git rebase , or rewriting history is a good rule in general, since they can be very useful features of a version control system, and it seems reasonable to teach them a course on source control.

+1
source share

The only thing users should be aware of is that Git does not mean another replacement for backups. Quite the opposite: Git is built to forget information.

For example, you cannot execute any hook scripts in the repository. Hooks are intentionally local to each instance of the repository. The same applies to conflict resolution "rerere".

In addition, the history of branches (for example, when there was such a fixation in which branch) was not recorded. Branches exist only as a pointer without history.

And last but not least, you can never be sure that the commit you made is actually stored in some other repository. It is very easy to forget about whether the commit really extends to other repositories, which can lead to disruption if you delete one repository that has changes.

The last way to get rid of the necessary incomplete work: stash uncommitted and unregistered files (which will not write them down), and then reset --hard (which will delete these files without a trace). My colleague is still angry when she recalls that it fails ...

+1
source share

Depending on what you mean by β€œentry-level programmers,” it would be nice to tell them to look at some user interfaces for git when they start. Good examples are Github for Windows and Github for Mac. They can be found at http://windows.github.com/ and http://mac.github.com/ respectively. These user interfaces show which files have not been tracked and allow you to commit them very easily. I would not call them a complete command line replacement, but this may be a good way to start learning them, such as things like commits and branching. There is currently no Linux interface on GitHub, but there are other interfaces at http://git-scm.com/downloads/guis . As they become familiar with the ideas of commits and branches, they can go to the command line to gain access to additional git features.

+1
source share

All Articles