Summary - First repository
- Git course
- Beginner
- Lesson 12/80
- 5 min
Combine init, add and commit to set up the first repository.
The first repository flow
Building the first repository takes three steps: start it with git init, create a file and put it on the stage with git add, then save it with git commit. A commit is a saved snapshot of the staged content; with the -m option you give it a short message. When these commands work together your first record exists.
git init
echo ilk satir > gunluk.txt
git add gunluk.txt
git commit -m "ilk kayit"Practice Complete the first repository
Create the gunluk.txt file and write ilk satir in it. Stage the file, save it quietly with the message ilk kayit, and print the contents of the file at the end.
Starter code
# 1) bu klasorunde depoyu sessizce baslat
# 2) gunluk.txt adinda bir dosya olustur
# 3) icine ilk satir yaz
# 4) dosyayi sahneye ekle
# 5) ilk kayit mesajiyla sessizce kaydet
# 6) dosyanin icerigini ekrana yazdirSample solution
git init -q
echo "ilk satir" > gunluk.txt
git add gunluk.txt
git commit -q -m "ilk kayit"
cat gunluk.txtExpected output
ilk satir
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does the git commit -m "ilk kayit" command do?
- It saves the staged content with a message Correct answer
- It creates a new repository
- It deletes the records and starts over
- It stages the gunluk.txt file
Explanation: git add stages content, while git commit saves the staged content together with the message you write with -m.
2 Write the message
git commit ____ "ilk kayit"
git commit -m "ilk kayit"
Explanation: To write the message on the command line you use the -m option; the others are not used for messages.
3 First repo flow
| Term | Meaning |
|---|---|
git init |
Starts the repository |
echo > gunluk.txt |
Creates the file |
git add |
Prepares the next snapshot |
git commit -m |
Saves a snapshot with a message |