Before doing any of this, remember that no learning method is perscriptive and will work for all people. This approach was very effective for me, it might not work as well for you! Modify or use parts of it as you see fit. I recommend spending several days going through the steps outlined below. It might seem like a large amount of time to spend not making progress on anything else, but you will have a much better understanding of git afterwards, and this will pay huge dividends in time.
- Start reading the Pro Git Book (https://git-scm.com/book/en/v2).
- If you've never used version control, there will be some stuff at the beginning about comparisons between git and other version control systems that might not make sense to you. Feel free to just ignore this, it's not important.
- After you have git installed and have learned about
git init, make a practice repository with a bit of content you wouldn't actually mind losing (e.g. a few small text files you just type something silly into). For example, the practice repo I used to learn git is here: https://github.com/porterjamesj/gitfool
- When you get to a section about a new command or concept, first read the section, and then practice what you learned on your practice repository to test your understanding.
- For example, when the book explains adding and committing files, create some new files in your practice repository and test
git adding and then
git commiting them. Similarly, when the book explains remotes and pushing, create a new repo on github (reading the book's chapter about Github might be helpful here), add it to your practice repository as a remote, and push to it.
- Don't be afraid to try combinations of commands whose results you're unsure of. When you want to try something that you're worried might break everything:
- Run the commmand(s) you are nervous about.
- Using what you've learned, try and understand what happened and fix it if something went wrong.
- This is going to be hard and frustrating. this is normal and OK, you will get better at it slowly and understanding will come with time.
- Keep in mind that your goal is to build a mental model of how git works, not just memorize commands. Again, This will be hard and confusing. The UI of the
gitcommand line tool is terrible, but there is structure underlying its behavior, you can learn this structure with deliberate practice, and the more you learn about it, the less painful and confusing using git will be for you.
- It's important to understand what git is doing in response to each command you type. To this end, you should use the tools available to you for introspecting git's behavior each time you do something. Tools for doing this include:
git status. I often type
git statusafter every git command I type, just to check my understanding and make sure it did the thing I was expecting.
git log, which gets more useful if you pass it a bunch of options (covered here in the book) so that it makes nicer drawings.
gitk, which are fancier repository visualizers.
- When you get to the end of chapter 3, stop reading and review the material so far rather than going on. Everying past this point in the book is not necessary for basic git proficiency. If you're interested in learning about more after you feel comfortable with the basics, the chapters on Github and Git Tools (chapters 6 and 7) are well worth spending time on.