Git Basics: Initialize and Commit
Duration: 5 min
What is a Git Repository?
A Git repository is a folder that contains your project files and a hidden .git directory that tracks all changes. When you initialize a repository with git init, Git starts tracking changes to files in that folder.
Creating Your First Repository
# Create a new project folder
mkdir my-ai-project
cd my-ai-project
# Initialize a Git repository
git init
# Check the status
git statusInitialized empty Git repository in /path/to/my-ai-project/.git/
On branch main
No commits yet
nothing to commitConfiguring Git
Before making commits, tell Git who you are. This information is attached to every commit you make.
# Configure your name
git config --global user.name "Your Name"
# Configure your email
git config --global user.email "your.email@example.com"
# Verify your configuration
git config --global --listuser.name=Your Name
user.email=your.email@example.comMaking Your First Commit
A commit is a snapshot of your project at a specific point in time. To make a commit, you first stage files with git add, then save them with git commit.
# Create a file
echo 'print("Hello, AI!")' > hello.py
# Check what changed
git status
# Stage the file
git add hello.py
# Commit with a message
git commit -m 'Add hello.py'
# View commit history
git logOn branch main
Initial commit
Changes to be committed:
new file: hello.py
[main (root-commit) a1b2c3d] Add hello.py
1 file changed, 1 insertion(+)
create mode 100644 hello.py💡 Tip: Write clear commit messages that describe what changed. Good: 'Add user authentication'. Bad: 'fix stuff'.
❓ What is the correct order for making a commit?