Create a Git repository and make your first commit
Description: Create a folder named my-notes, make it a Git repository, create a file notes.txt with some text, and save it in a first commit with the message “Add notes”.
Hint:
- Use
git initinside the folder. - A file must be staged with
git addbefore the commit.
Solution
Terminal output
$ mkdir my-notes
$ cd my-notes
$ git init
Initialized empty Git repository in /home/robin/my-notes/.git/
$ echo "My first note" > notes.txt
$ git add notes.txt
$ git commit -m "Add notes"
[main (root-commit) 6927e03] Add notes
1 file changed, 1 insertion(+)
create mode 100644 notes.txt
$ git log –oneline
6927e03 (HEAD -> main) Add notes
How it works
git initcreates the hidden.gitfolder, which makes the folder a repository.git addstages the file, andgit commit -msaves it with the message.git log --onelineshows the new commit.
Read Git Init and Git Commit.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |