Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Git as safe as possible for beginners? [closed]

Tags:

git

I'm currently working on a course module for programming scientists, on Git and version control. One of the benefits I'm trying to convey (amongst others), is that using VC can safeguard you against loss of work. But of course, as is well-known, Git gives you ample opportunity to shoot yourself in the foot. It'd be a shame to have students in the course loose work because of using a system that was supposed to prevent that from happening in the first place :-)

My question: would you have tips for things you could teach people (commands, workflows, tricks) that steer them out of trouble when using Git?

Specifically, this applies mostly to people with a solo workflow, without prior Git experience, and possibly beginner-level programmers.

Examples of the kind of tips I'm aware of:

  • Push your code to something like GitHub or BitBucket regularly. Also, please make backups, too :)

  • 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 history rewriting, especially when you're still learning.

Thanks!

like image 347
onnodb Avatar asked Feb 11 '14 21:02

onnodb


2 Answers

I think you're doing things more complicated than needed.

To be able to recover previous state, regular commits to a local repo is all that is required. You don't have to introduce branching or merging at this stage. Maybe tagging as a way to get back to specific versions.

To reduce the risk of loss of code due to a lost computer / crashed hard drive proper backups is a good advice. But that is the same for everything, not just code.

If you want to introduce code sharing, pushing to github or bitbucket is an option. As long as you only push and you're the only one pushing it is very simple.

like image 53
Anders Abel Avatar answered Oct 05 '22 22:10

Anders Abel


The most general rule would be: ensure you know what a command does before using it.

It could be declined in more specific tips:

  • More generally that avoiding git rebase, we could say avoiding to change the history.
  • Avoid using the flag -f on a comment (push, clean, ...)

Having a safety net before doing something potentially dangerous is indeed always a good idea. However, no need to copy the whole directory : just putting a tag on your original commit to be able to checkout it if things goes wrong is enough and less cumbersome.

like image 38
gturri Avatar answered Oct 05 '22 21:10

gturri