Making your first commit
Last updated
Was this helpful?
Last updated
Was this helpful?
With the explanation and background context covered in the previous pages, these next few sections will walk you through working with a Git repository.
First, make sure you have git. You can do this by running git --version
in your terminal. If you get an error message, you don't have it, or it's not set up properly and you should get it from . As with any tool you install, don't forget to add it to your PATH
.
To start, make a new directory and run git init
inside of it
Next, let's add a simple Hello World in Python
Now let's see what Git has to say
Let's break this down:
On branch
master
Git will always start by reminding you what branch you're on. In this case, that's master
, but convention is actually to use main
. Let's create that:
Moving on:
nothing added to commit but untracked files present (use
git add
to track)
Git won't touch any files it doesn't already know about (called tracked files), so let's add our new file:
Now we're on the main
branch, and we no longer have a warning about untracked files. Now Git is ready to commit, so let's make a new commit with a message:
You can use git commit -m "your message"
and git switch -c
as shorthand
The output here confirms your branch, commit ID (also called the commit hash), message, and what changed. Running git status
confirms that our commit went through and that we're clear to start making more changes:
Now that you've set up your repository and branch, the process will be the same for future changes: make changes, git add
the files, then git commit
with a message. Let's review that last commit
This has a lot of output, but you can clearly see the commit ID, author, date, message, which files were edited and even the diff for each file.