Git Basics from the Command Line
Learn essential Git commands for version control, including committing, branching, and merging.
Git Basics from the Command Line is a free Linux Command Line Mastery lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Command Line Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What is Git?
Welcome to Git basics! Git is a powerful Version Control System (VCS). Think of it as a super-smart history book for your code.
It tracks every change you make, letting you revert to older versions, collaborate with others, and manage different features without stepping on toes. It's essential for modern software development!
Starting a Git Project
To begin tracking a project with Git, you first need to initialize a repository. This creates a special .git folder in your project, where Git stores all its tracking information.
Use the git init command in your project's root directory.
mkdir my_project
cd my_project
git initStaging Your Changes
Before saving your work, Git uses a 'staging area'. This is like a rough draft space where you select which changes you want to include in your next save.
The git add command is used to add files or changes to this staging area.
echo "My first line." > README.md
git add README.mdSaving Your Work (Commit)
Once changes are staged, you 'commit' them. A commit is a snapshot of your project at a specific point in time, with a descriptive message.
Use git commit -m "Your message" to save staged changes to your repository's history.
git commit -m "Initial commit: Added README.md"Viewing Project History
Git keeps a detailed log of all your commits. You can review this history to see who made what changes and when.
The git log command displays your repository's commit history. The --oneline option provides a concise view.
git log --onelineParallel Development with Branches
Branches are a core concept in Git. They allow you to diverge from the main line of development and continue working without affecting the main project.
- Work on new features.
- Fix bugs without breaking stable code.
- Experiment with new ideas.
The main (or master) branch is typically the stable version.
Creating a New Branch
To start a new line of development, you create a new branch. This doesn't move you to the new branch yet; it just creates it.
The git branch <branch-name> command creates a new branch. You can list all branches with just git branch.
git branch feature/login
git branchSwitching Between Branches
After creating a branch, you need to switch to it to start working on that specific line of development. Your files will reflect the state of that branch.
Use git switch <branch-name> to move to an existing branch. It's the modern way to navigate branches.
git switch feature/login
# Now you are on the 'feature/login' branchMerging Branches
Once you've finished work on a feature branch, you'll want to integrate those changes back into your main development line, usually the main branch.
First, switch to the target branch (e.g., main), then use git merge <source-branch> to bring in the changes.
git switch main
git merge feature/loginGit Workflow Check
You've learned the core steps for managing changes with Git. Let's test your understanding of how to save your work.
Git Basics Summary
Great job! You've learned the fundamental Git commands:
git init: To start a new repository.git add: To stage changes for a commit.git commit: To save staged changes to history.git log: To view your project's commit history.git branch: To create and list branches.git switch: To move between branches.git merge: To combine changes from different branches.
These commands form the backbone of managing your code with Git!
Frequently asked questions
Is the “Git Basics from the Command Line” lesson free?
Yes — the full text of “Git Basics from the Command Line” is free to read here on the web, and the Linux Command Line Mastery course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Command Line Mastery course, upgrade to CoddyKit PRO.
What will I learn in “Git Basics from the Command Line”?
Learn essential Git commands for version control, including committing, branching, and merging. You practise Linux Command Line Mastery with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Linux Command Line Mastery?
No prior experience is required. Linux Command Line Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Git Basics from the Command Line” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Linux Command Line Mastery lesson?
Yes. Every Linux Command Line Mastery lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.