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 init inside the folder.
  • A file must be staged with git add before 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 init creates the hidden .git folder, which makes the folder a repository.
  • git add stages the file, and git commit -m saves it with the message.
  • git log --oneline shows 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.