Many of my students often ask for a simple guide to get started with Git—a collection of essential commands to kick off their Git journey. So, here’s a concise list of beginner-friendly Git commands to help you become productive right away and set you on the path to becoming a Git ninja! 🥷
In this guide, we’ll focus on using Git commands directly in the terminal. Ready? Open up your terminal, and let’s dive in!
- Initialize a Git Repository: git init The git init command sets up a new Git repository in your project.
Command | Description |
---|---|
mkdir gitPractice |
Create a new project directory |
cd gitPractice |
Navigate to the project directory |
git init |
Initialize the Git repository |
This creates an empty .git directory inside your project, signaling that Git is now tracking your files.
- Check the Status of Your Files: git status The git status command shows you the current state of your files—whether they’re untracked, staged for commit, or unchanged.
Command | Description |
---|---|
touch git_practice.txt |
Create a new file |
git status |
Check the status |
You’ll see the new file (git_practice.txt) listed as untracked. Git isn’t tracking it yet, so it won’t be part of your next commit.
- Stage Files for Commit: git add Use the git add command to tell Git to start tracking a file or prepare it for commit.
Command | Description |
---|---|
git add git_practice.txt |
Add a specific file |
git add . |
Add all files in the directory |
Running git status again will show the files as staged and ready to commit.
- Commit Your Changes: git commit Committing saves your staged changes into the repository’s history.
Examples:
Command | Description |
---|---|
git commit |
Commit without a message (prompts for one) |
git commit -m "Initial commit" |
Commit with a message |
- Switch or Create Branches: git checkout Branching lets you work on features or fixes without affecting the main codebase.
Examples:
Command | Description |
---|---|
git checkout -b feature_x |
Create a new branch and switch to it |
git checkout develop |
Switch to an existing branch |
Pro Tip: If the branch you’re switching to doesn’t exist, Git will notify you.
- Merge Changes Between Branches: git merge Merging integrates changes from one branch into another.
Example:
Command | Description |
---|---|
git checkout master |
Switch to the master branch |
git merge develop |
Merge the develop branch into master |
Now, the changes made in the develop branch are part of the master branch.
Bonus Tip: Stay Organized!
After making changes, use git status to check what’s staged, committed, or untracked. And always write meaningful commit messages—future you (and your team) will thank you. 😊
Wrapping Up
I hope this guide helps you get a solid start with Git. These commands are just the tip of the iceberg, but mastering them will make you more productive and confident as you work with Git repositories.
Keep smiling, and stay tuned for more tips in the next blog! 😊✨
Top comments (0)