Using Git

This post is a brief introduction to using Git using the command-line tool git. You would enter these commands in a bash shell. You can directly use a bash shell in macOS, Linux, and Windows WSL2. On Windows, you can also use git bash, which is part of Git for Windows.

Git Setup

Once you have a bash shell with the git command, you set up your local git account with your full name and email. Here is how I set up my account:

git config --global "Michael L. Collard"
git config --global ""

You only need to set up your account once on a particular computer.

You can then verify that you set it up correctly:

git config --global
git config --global

Git Local Repository Setup

Then you clone the repository. Cloning creates a local repository that is a copy of your repository at GitHub. Get the URL for the repository from GitHub.

git clone

Git Workflow on Rainfall

Commands for a basic Git workflow on rainfall.cpp:

Edit files locally, e.g., add a header comment to the file rainfall.cpp  
Commit current changes to the local repository git commit -am "Add a header comment"
Update the remote repository from the local repository git push

Other Useful Commands

Other useful commands in Git:

View commit log git log
Update the local repository from the remote repository (e.g., GitHub) git pull
View current staged and modified files git status
View difference of modified files git diff
View difference of staged files git diff --cached