- To double-check that Git is installed, type git
--version
:
git --version
You should see output that looks something like this example:
git version 2.38.1
-
To configure Git, you must define some global variables:
user.name
anduser.email
. Both are required for you to make commits. -
Set your name in Cloud Shell with the following command. Replace
<USER_NAME>
with the user name you want to use.
git config --global user.name "<USER_NAME>"
- Now, use this command to create a user.email configuration variable, replacing
<USER_EMAIL>
with youre-mail address
:
git config --global user.email "<USER_EMAIL>"
- Run the following command to check that your changes worked:
git config --list
Git works by checking for changes to files within a certain folder. We'll create a folder to serve as our working tree (project directory) and let Git know about it, so it can start tracking changes. We tell Git to start tracking changes by initializing a Git repository into that folder.
- Create a folder named Cats. This folder will be the project directory, also called the working tree. The project directory is where all files related to your project are stored.
mkdir Cats
- Change to the project directory by using the
cd
command:
cd Cats
- Now, initialize your new repository and set the name of the default branch to
main
:
git init --initial-branch=main
git init -b main
- Now, use a
git status
command to show the status of the working tree:
git status
Git responds with this output, which indicates that main is the current branch. (It's also the only branch.) So far, so good.
OUTPUT: On branch main No commits yet nothing to commit (create/copy files and use "git add" to track)
- Use an ls command to show the contents of the working tree:
ls -a
- Use a touch command to create a file named
index.html
:
touch index.html
touch
updates a file's last-modified time if the file exists. If the file doesn't exist, Git creates an empty file with that file name.
- Now, use git status to get the status of the working tree:
git status
Git responds by informing you that nothing has been committed, but the directory does contain a new file:
No commits yet Untracked files: (use "git add ..." to include in what will be committed) index.html nothing added to commit but untracked files present (use "git add" to track)