Basic Commands
Git Configuration
Set up your name and email
Create a new repository
To create a new repository, simply run git init in the directory you want to version control.
For example:
Basic Workflow
Note
My suggestion is to use VSCode which has integrated support for Git. You can stage and commit changes directly from the editor. VSCode also has a useful extension called GitLens which allows you to see the history of a file when you are editing it and who made the changes. Still learn the commands below — you will need them on remote Azure servers where there is no VSCode GUI.
Here is an example of a basic workflow if you were doing things manually using Git.
Create a new file
| Bash | |
|---|---|
Add the file to the staging area
| Bash | |
|---|---|
Commit the file
| Bash | |
|---|---|
Check the status of your repository
| Bash | |
|---|---|
Branching
Within a git repository, you can create branches to work on different features or bug fixes. Branching allows you to isolate changes and work on them independently.
For branching strategy I suggest you consider the GitHub flow model. https://docs.github.com/en/get-started/using-github/github-flow
When you first create a repository, you are on the main branch. You can create a new branch using the following command:
| Bash | |
|---|---|
This command creates a new branch called new-branch and switches to it. (Modern Git also offers git switch -c new-branch; checkout still works everywhere.)
You can switch between branches using the following command:
To see a list of branches in your repository, run:
| Bash | |
|---|---|