← Back to Home
πŸ“¦

Git Basics β€” Your First Repository

The everyday Git commands: init, status, add, commit, log, and push.

⏱12 min readπŸ“šDevOps Fundamentals

Time to use Git for real. In this lesson you’ll create a repository, save snapshots of your work, and push it to GitHub.


🎯 Learning Objectives

By the end of this lesson you will:


Create a Repository

bash
mkdir my-project && cd my-project
git init

git init creates a hidden .git folder β€” that’s where Git stores your entire history.


The status β†’ add β†’ commit Cycle

Create a file, then check what Git sees:

bash β€” 80Γ—24
student@devops:~$echo '# My Project' > README.md && git status

Stage the change, then commit it as a snapshot:

bash
git add README.md          # stage one file
git add .                  # or stage everything
git commit -m "Add project README"

⚠ Write meaningful commit messages

git commit -m "stuff" helps no one. Describe what changed and why: "Fix login redirect on expired session". Your future self and your teammates read these constantly.


Read the History

bash
git log              # full history
git log --oneline    # compact, one line per commit
bash β€” 80Γ—24
student@devops:~$git log --oneline

Push to GitHub

Create an empty repository on GitHub, then connect and push:

bash
git remote add origin https://github.com/your-user/my-project.git
git branch -M main
git push -u origin main

After the first push -u, future uploads are just git push.

πŸ’‘ Use SSH to skip password prompts

Remember the SSH keys from the Linux section? Add your public key to GitHub (Settings β†’ SSH keys) and use the SSH remote git@github.com:your-user/my-project.git to push without typing credentials.


πŸ§ͺ Hands-on Lab

πŸ“

Create and Commit a Repository

  1. Create a folder git-lab and run git init
  2. Create a README.md file
  3. Stage and commit it with a clear message
  4. View the history with git log --oneline

🧠 Knowledge Check

Knowledge Check

Which command turns a normal folder into a Git repository?

Knowledge Check

What is the correct order to save and share a change?


πŸ’Ό Interview Preparation

Interview Q&A

What is the difference between the working directory, the staging area, and the repository?


Summary

You created a repo, staged and committed changes, read the log, and pushed to GitHub. These commands are the ones you’ll run dozens of times a day.

Up Next

Branching & Pull Requests

You've mastered this lesson. Continue your journey to becoming a DevOps Engineer.

Start Next Lesson→