How Beginners Should Learn Git
Version control records every change in software — every release, every bug. It runs through the entire lifecycle of software, from birth to death. Please treat every commit with care, and write your commit messages as if you were recording history.
Git is currently the most popular version control system and a great choice. As a competent software developer, you should be proficient in using it. You can construct practice scenarios to work through git commands, such as:
- Create a repo on GitHub and push code to it. (clone, add, commit, push)
- Create a new branch
devfrommain, make changes, then merge the code back intomainvia a PR. (checkout, pr, branch) - Create a new branch
devfrommain, make changes and commit. Then switch back tomain, make changes, and push to the remote branch. Switch back todevand rebase the commits frommaininto the current branch. (practice rebase and reset) - Create a new branch
devfrommain, create 7 commits, then squash them into a single commit. (practice using reset or rebase) - Create a new branch
devfrommain, create 7 commits, then: squash the 7th commit into the 1st, drop the 2nd commit, edit only the commit message of the 3rd, edit only the commit author of the 4th, and modify the code in the 6th commit. (practice rebase and how to clean up commit history) - Fork a repo, clone it locally, and make changes. After new commits appear on the upstream repo’s main branch, sync your local code with the upstream repo. (practice remote, fetch, rebase)
These are just a few example scenarios — you can write more based on your own needs. It is recommended to practice on the command line, and also to use the command line during your regular development workflow. Avoid relying on the UI provided by your IDE.
Once you have a handle on Git, it’s also worth learning about common Git workflows:
- Git flow
- Trunk-based
- Feature branching
- Forking Workflow
Learning resources:
- Official documentation: Git - Documentation (git-scm.com). The official docs are already very thorough.
- A book — Pro Git: https://github.com/progit/progit2/releases/download/2.1.338/progit.pdf