*By default the active branch in a git repo is called master, however the default active branch for a repo created in GitHub is called main.
| Type | Command | Function |
|---|---|---|
| ONE TIME SETUP | git config --global user.name “[firstname lastname]” | Set a name that is identifiable for credit when review version history |
| ONE TIME SETUP | git config --global user.email “[valid-email]” | Set an email address that will be associated with each history marker |
| ONE TIME SETUP | git config --global color.ui auto | Set automatic command line coloring for Git for easy reviewing |
| SETUP & INIT | git init | Initialize an existing directory as a Git repository |
| SETUP & INIT | git clone [url] | Retrieve an entire repository from a hosted location via URL |
| STAGE & SNAPSHOT | git status | Show modified files in working directory, staged for your next commit |
| STAGE & SNAPSHOT | git add [fileName] OR git add . | |
| Add a file as it looks now to your next commit (stage) | ||
| Use . to add all files (only modified ones get added) | ||
| STAGE & SNAPSHOT | git reset [fileName] OR git reset . | |
| Unstage a file while retaining the changes in working directory | ||
| Use . to unstage all files (only modified ones get unstaged) | ||
| STAGE & SNAPSHOT | git diff | Diff of what is changed but not staged |
| STAGE & SNAPSHOT | git commit -m “[descriptive message]” | commit your staged content as a new commit snapshot |
| BRANCH & MERGE | git branch | List your branches. a * will appear next to the currently active branch |
| BRANCH & MERGE | git branch [branch-name] | |
| Create a new branch at the current commit | ||
| BRANCH & MERGE | git branch -M [oldbranch] [newbranch] | Rename an existing git branch , if oldbranch is not given like git branch -M main it will rename the current active branch to main. |
| BRANCH & MERGE | git checkout [branch-name] | Switch the active branch to another one |
| BRANCH & MERGE | git checkout -b [new-branch] | Creates a new branch and swithes the active branch to the new-branch , it runs 2 commands |