Your First Repository: init, add, commit
Harry
· 14 Sep 2026
· 2 views
Advertisement
Set up who you are
Git stamps every commit with your name and email. Configure them once, globally:
git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"
Create a repository
mkdir myproject && cd myproject
git init
git init creates the hidden .git folder – the repository. Your files are now trackable. Check the state at any time with the command you will run most often:
git status
Stage and commit
Committing is two steps: stage the exact changes you want, then record them.
git add README.md # stage one file
git add . # stage everything changed
git commit -m "Add project README"
Staging lets you craft a commit deliberately – you can change ten files but commit only the three that belong together. A good commit message says why, in the imperative mood: “Add login validation”, not “fixed stuff”.
Ignore files you never want tracked
Build output, dependencies and secrets should not be in history. List them in a .gitignore file at the project root:
node_modules/
target/
.env
*.log
Read the history
git log --oneline --graph # compact, visual history
git show HEAD # what the latest commit changed
git diff # unstaged changes vs last commit
Key points
- Set your name and email once with
git config --global. git initstarts a repo;git statusshows what is staged and what is not.- Stage with
add, record withcommit -m; write messages that explain why. - Use
.gitignoreto keep build output and secrets out of history.