Git Course
Repositories (Repos)
A repository (repo) is a collection of files tracked by Git. You can create a new repository or clone an existing one:
Creating a new repository
To initialize a new git repository
git init
I see this
D:\praveenoruganti\codeworkspace\gitworkout\sample1>git init Initialized empty Git repository in D:/praveenoruganti/codeworkspace/gitworkout/sample1/.git/
This creates a hidden .git folder in the project directory, which Git uses to track changes.
Cloning an existing repository
If you want to work on an existing project, clone it with:
git clone <repository-url>
Lets clone the sample1 repo from orugantipraveen organization.
git clone https://github.com/orugantipraveen/sample1.git
I see this
D:\praveenoruganti\codeworkspace\gitworkout>git clone https://github.com/orugantipraveen/sample1.git Cloning into 'sample1'... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) Receiving objects: 100% (3/3), done.
Staging changes
When you modify files in your working directory, Git won't track them until you stage them.
To stage a file we need to use the below command.
git add <filename>
To stage all changes we need to use the below command.
git add .
Let's try these 2 above commands for staging files in our sample1 repo.
I created File1.txt in the sample1 folder and need to stage it.
D:\praveenoruganti\codeworkspace\gitworkout\sample1>git add File1.txt
I created 2 files File2.txt and File3.txt and i need to stage all the changes.
D:\praveenoruganti\codeworkspace\gitworkout\sample1>git add .
Committing changes
Once you've staged your changes, commit them to your local repository.
git commit -m "Your commit message"
A commit represents a snapshot of your project at a particular point in time.
Let's execute the above command in sample1 folder.
D:\praveenoruganti\codeworkspace\gitworkout\sample1>git commit -m "Added File1, File2 and File3 text files" [main 3638d72] Added File1, File2 and File3 text files 3 files changed, 3 insertions(+) create mode 100644 File1.txt create mode 100644 File2.txt create mode 100644 File3.txt
Viewing the commit history
To see a log of all commits we need to execute below command.
git log
I see this.
D:\praveenoruganti\codeworkspace\gitworkout\sample1>git log commit 3638d72435915062c756872fdec5a1aad2fc3abb (HEAD -> main) Author: Praveen Oruganti <praveenoruganti@gmail.com> Date: Mon Feb 17 09:40:00 2025 +0530 Added File1, File2 and File3 text files commit ffde5d9a9ceaa86645bf8b240fa87bed5ac4b370 (origin/main, origin/HEAD) Author: Praveen Oruganti <praveenoruganti@gmail.com> Date: Mon Feb 17 09:31:55 2025 +0530 Initial commit
Push the changes
Lets execute the below command to push the changes to sample1 repo.
git push
I see this.
D:\praveenoruganti\codeworkspace\gitworkout\sample1>git push info: please complete authentication in your browser... Enumerating objects: 6, done. Counting objects: 100% (6/6), done. Delta compression using up to 8 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (5/5), 392 bytes | 392.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0) To https://github.com/orugantipraveen/sample1.git ffde5d9..3638d72 main -> main