Firstly, this linked guide is a good overview of what git is, but it may be a bit to absorb all at once: https://rogerdudler.github.io/git-guide/
Essentially - commit when you want to save your work. This could be when you complete a full set of work and the code passes all tests. It could be earlier as well, depending on how many other people are working on the project at the same time.
git init
initializes an empty git repository (a local one). You will need to do this before you can do anything else for git.git add -A
will add all files in the current directory to the staging area.git commit
will open up $EDITOR (hopefully vim) and require you to enter a message about the changes before it saves them to the git tree.git commit -a
will add all edited files to the staging area, and begin a commit.The above is useful for tracking and saving work as you go (especially important when working on BIG project)
The next information is for working with big groups of people, and tracking your work with better detail.
git checkout -b <branchname>
creates a new branch and switches to it.git branch
lists the local branchesgit checkout <branchname or commit hash>
switches to a branch or specific commit (handy for seeing previous versions of the code)