Introduction to Git

Git is a popular version control system used to keep track of changes to various files.

Setting up Git

Setup git by configuring your name and email address in git.

$ git config --global user.name "Anand Chitipothu"
$ git config --global user.email "anand@example.com"

Please use your name and email address in the example above. Also, make sure the email address is same as what you have used when creating an account on github.

Setup ssh-keys

$ ssh-keygen -t ed25519 -C anand@my-laptop-name

That will output the following:

Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/anand/.ssh/id_ed25519):

Just press Enter.

Enter passphrase (empty for no passphrase):

If you are using your own laptop, leave this empty. If you using the lab computer, pick a strong passphrase as that allows pusing any changes to your repositories on github.

Git Usage Complexity

Level 1

Use git for managing your own projects.

Level 2

Use git to collaborate with a small number of known people.

Level 3

Collaborate with unknown, untrusted people.

Cloning a Repository

Run these steps after creating your repository and adding your ssh-keys.

$ cd
$ pwd
/home/anand
$
$ git clone git@github.com:anandology/git-practice.git
Cloning into 'git-practice'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (4/4), done.
$ cd git-practice/
$ code .

Replace the repository URL in the example with the URL of your repoistory clone URL.

Commiting changes

Create a new file.

$ seq 10 > 10.txt

Add the file to git staging area.

$ git add 10.txt
$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   10.txt

Commit the changes.

$ git commit -m "Added 10.txt"
[main b8c9a60] added 10.txt file
 1 file changed, 10 insertions(+)
 create mode 100644 10.txt

And push the changes.

$ git push
...
To github.com:anandology/git-practice.git
   b8c9a60..e53d588  main -> main

References