Labs · DevOps
Lab: Create a Git Repository with Three Clean Commits, a .gitignore That Hides Secrets, and One Remote
Course: DevOps · Chapter 2: Git, GitHub and Git Bash · Lesson: 2.13 Lab: three commits and one remote
Chapter 2 explains Git, GitHub and the staging area; this lab does it once, end to end.
Chala mitrano! Aaj aapan aaplya laptop var pahila Git repo banvuya. Three small commits, one .gitignore, ani ek remote. Ekdum simple aahe.
Suppose we are…
Suppose we have just joined an Infosys project team as a fresher. On day one the team lead says: "Start the badge API, commit small, and never push the .env file." Many freshers zip the folder and email it. That has no history and no review. Git keeps every change with a message, and GitHub keeps a shared copy for the team.
In this lab we create the repo from zero, make three clean commits, prove that the secret file is ignored, and connect one remote.
Goal of this lab
By the end you will have:
- A local repository with exactly three commits and clear messages.
- A
.gitignorethat keeps.env,node_modules/and*.pemout of Git. - A remote named
origin, checked withgit remote -v.
What you need
- Git installed (
git --versionshows 2.x). - Git Bash on Windows, or Terminal on Mac and Linux.
- A free GitHub account and one empty repository you created yourself (no README).
- 30 minutes.
Part 1: Create the repository
Tell Git who you are (only once per laptop):
git config --global user.name "Your Name" git config --global user.email "you@example.com" git config --global init.defaultBranch mainCreate a folder and turn it into a repository:
mkdir badge-api-hello cd badge-api-hello git initWhat you should see:
Initialized empty Git repository in .../badge-api-hello/.git/Check the state. Get used to running this before every add:
git statusWhat you should see:
On branch mainandNo commits yet.
Part 2: Three small commits
Commit 1: a tiny app file.
cat > app.js <<'EOF' const http = require("http"); http.createServer((req, res) => res.end("badge api ok\n")).listen(3000); EOF git add app.js git commit -m "Add hello badge API on port 3000"What you should see:
1 file changed, 2 insertions(+)Commit 2: a
.gitignoreso junk and secrets never enter Git.cat > .gitignore <<'EOF' .env node_modules/ *.pem *.log EOF git add .gitignore git commit -m "Ignore env files, keys, logs and node_modules"Commit 3: a short README.
printf "# badge-api-hello\n\nRun: node app.js\nOpen: http://localhost:3000\n" > README.md git add README.md git commit -m "Add README with run steps"Read the story of your repo:
git log --onelineWhat you should see: three lines, newest first, each with a short id and your message.
c3d4e5f Add README with run steps b2c3d4e Ignore env files, keys, logs and node_modules a1b2c3d Add hello badge API on port 3000
Part 3: Prove the secret file is ignored
Create a fake secret file. Never put a real password in a lab.
echo "DB_PASSWORD=fake-lab-value" > .env git statusWhat you should see:
nothing to commit, working tree clean. The.envfile is not listed, because.gitignorehides it.Ask Git why a file is ignored:
git check-ignore -v .envWhat you should see:
.gitignore:1:.env .env
Part 4: Connect one remote
On GitHub, open your empty repository and copy its HTTPS or SSH URL. Add it as
origin(replace YOURUSER):git remote add origin https://github.com/YOURUSER/badge-api-hello.git git remote -vWhat you should see: two lines for
origin, one(fetch)and one(push).Push only if your sign-in already works (a token in the credential manager, or an SSH key):
git push -u origin mainIf push asks for a password, do not type your GitHub account password. Use a personal access token or set up SSH (lesson 2.12). The three local commits already finish this lab.
What you should see:
main -> mainandbranch 'main' set up to track 'origin/main'.
Ravindra Bagale's Tip
Run git status before every git add .. Two seconds of reading saves you from committing a key file that you then have to rotate.
Common mistakes
| Mistake | What happens | Fix |
|---|---|---|
Typing git add . before creating .gitignore | .env or node_modules gets staged | git rm --cached .env, add it to .gitignore, commit again |
Running git remote add origin twice | error: remote origin already exists. | Use git remote set-url origin <url> |
| Using the GitHub account password on push | Authentication failed | Use a personal access token or an SSH key |
| One giant commit called "update" | Nobody can review or undo one part | Small commits with a clear verb: Add, Fix, Remove |
Self-check checklist
0 of 4 done
Try-at-home challenge
Change the message in app.js, run git diff to see the change, then undo it with git restore app.js. Write down when git commit --amend is safe (only before you push).
Samajla ka? Small commits, clean .gitignore, one remote. Aata pudhe jaauya branches and pull requests madhe.