611 lines
13 KiB
Markdown
611 lines
13 KiB
Markdown
# 1. What is Git and Version Control
|
|
|
|
Assignment:
|
|
|
|
-Write down (in your own words) what problem Git solves.
|
|
-Find one real-life example where multiple people edit the same file (school project, code, Google Docs).
|
|
-Answer: Why is version control better than emailing files back and forth?
|
|
---
|
|
Git is mainly created to keep (1)control of version history especially during development - it makes sure nothing is lost due to human error and helps keep track of changes and by who. This is important to (2)ensure efficiency during any project - takes up lesser time to fix errors and go back and forth between versions if necessary. Files are also (3)accessible remotely and doesn't require a specific device.
|
|
|
|
Examples: Group projects presentations, research papers worked on by multiple people
|
|
|
|
Emailing back and forth takes a lot of disk space and memory as opposed too version control that keeps track of specific changes and times. Emailing back and forth requires manual intervention to keep track of version, prone to error and confusion, sometimes data could get lost in the pile. Git is not managed by a singular person, which makes sure all files are accounted for and treated the same - makes it easier to look back and understand the process each version or file went through because they all underwent the same set of file managment rules.
|
|
|
|
|
|
# 2. Installing Git & Configuring User Info(COMPLETED)
|
|
|
|
Assignment:
|
|
|
|
Install Git (if not already installed).
|
|
|
|
Run:
|
|
|
|
git --version
|
|
git config --global user.name "Your Name"
|
|
git config --global user.email "your@email.com"
|
|
|
|
Verify with:
|
|
|
|
git config --list
|
|
|
|
### My Results
|
|
```
|
|
user.name=Magdel
|
|
user.email=raokhshna.m@comorin.co
|
|
```
|
|
|
|
|
|
# 3. Initializing a Repository
|
|
|
|
Assignment:
|
|
|
|
Create a new folder git-practice-<<your_name>>.
|
|
|
|
Inside, run:
|
|
|
|
git init
|
|
|
|
Verify that a .git folder is created.
|
|
|
|
Run git status and note the message (it should say “No commits yet”).
|
|
|
|
### My work
|
|
|
|
`mkdir git-practice-Mag`
|
|
|
|
`git init `
|
|
|
|
`ls -a`
|
|
verify folder
|
|
|
|
`git status`
|
|
nothing added to commit but untracked files present (use "git add" to track)
|
|
|
|
|
|
# 4. Working Directory, Staging, and Commits
|
|
|
|
Assignment:
|
|
|
|
In git-practice-<<your_name>>, create a file notes.txt.
|
|
|
|
Run:
|
|
|
|
git status
|
|
|
|
Observe which area (untracked → staged → committed) the file is in as you do:
|
|
|
|
git add notes.txt
|
|
git commit -m "Add first notes file"
|
|
git status
|
|
|
|
Write down how the status changed after each command.
|
|
|
|
### My work
|
|
|
|
`cd git-practice-Mag` go to Directory
|
|
|
|
`touch notes.txt ` creates file
|
|
|
|
`git status` notes.txt in the list of yet to be commit
|
|
|
|
|
|
`git add notes.txt`
|
|
`git status`
|
|
|
|
`git commit -m "Add first notes file"`
|
|
|
|
#### Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~ (master)
|
|
$ git commit -m "Add first notes file"
|
|
[master (root-commit) 5287a29] Add first notes file
|
|
1 file changed, 0 insertions(+), 0 deletions(-)
|
|
create mode 100644 notes.txt
|
|
|
|
```
|
|
|
|
`git status`
|
|
|
|
|
|
# 5. Adding & Committing Files
|
|
|
|
Assignment:
|
|
|
|
Add another file todo.txt.
|
|
Stage and commit with a meaningful message.
|
|
Modify todo.txt, then commit the change again.
|
|
Run git log --oneline to see both commits.
|
|
|
|
### My work
|
|
|
|
`cd git-practice-Mag`
|
|
|
|
`touch todo.txt`
|
|
|
|
`git add todo.txt` stage
|
|
|
|
`git commit -m "List of tasks you need to complete"` commit
|
|
|
|
#### Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-practice-Mag (master)
|
|
$ git commit -m "List of tasks you need to complete"
|
|
[master 3a3ab4d] List of tasks you need to complete
|
|
1 file changed, 0 insertions(+), 0 deletions(-)
|
|
create mode 100644 git-practice-Mag/todo.txt
|
|
```
|
|
|
|
### My work
|
|
echo "Task 1" >> todo.txt modify text
|
|
git add todo.txt
|
|
git commit -m "Add a task" commit changes
|
|
|
|
|
|
#### Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-practice-Mag (master)
|
|
$ git commit -m "Add new task"
|
|
[master b8c2503] Add new task
|
|
1 file changed, 1 insertion(+)
|
|
```
|
|
### My Work
|
|
`git log --oneline`
|
|
|
|
#### Result
|
|
```
|
|
git log --oneline Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-practice-Mag (master)
|
|
$ git log --oneline
|
|
b8c2503 (HEAD -> master) Add new task
|
|
3a3ab4d List of tasks you need to complete
|
|
5287a29 Add first notes file
|
|
```
|
|
|
|
|
|
# 6. Viewing Commit Logs & Diffs
|
|
|
|
Assignment:
|
|
|
|
Run:
|
|
|
|
git log
|
|
git log --oneline --graph
|
|
git diff
|
|
|
|
Edit notes.txt and check the changes with git diff before staging.
|
|
|
|
Stage and commit, then run git diff commit1 commit2 to see what changed between commits.
|
|
|
|
### My work
|
|
`git log`
|
|
#### Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-practice-Mag (master)
|
|
$ git log
|
|
commit b8c2503d1770ddf362d4862ec5f7095204d35015 (HEAD -> master)
|
|
Author: Magdel <raokhshna.m@comorin.co>
|
|
Date: Sun Aug 17 21:01:52 2025 +0530
|
|
|
|
Add new task
|
|
|
|
commit 3a3ab4dba4da1cab63238add554e247d6d7e9f38
|
|
Author: Magdel <raokhshna.m@comorin.co>
|
|
Date: Sun Aug 17 20:53:48 2025 +0530
|
|
|
|
List of tasks you need to complete
|
|
|
|
commit 5287a291bc0e9cc6bcbf43e1d7199c9e0a2db3e0
|
|
Author: Magdel <raokhshna.m@comorin.co>
|
|
Date: Sun Aug 17 20:47:40 2025 +0530
|
|
|
|
Add first notes file
|
|
```
|
|
|
|
### My work
|
|
`git log --oneline --graph`
|
|
|
|
#### Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-practice-Mag (master)
|
|
$ git log --oneline --graph
|
|
* b8c2503 (HEAD -> master) Add new task
|
|
* 3a3ab4d List of tasks you need to complete
|
|
* 5287a29 Add first notes file
|
|
```
|
|
|
|
### My work
|
|
|
|
`echo "Task 2" >> todo.txt`
|
|
|
|
`git add todo.txt`
|
|
|
|
`git commit -m "Add task 2"`
|
|
|
|
#### Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-practice-Mag (master)
|
|
$ git commit -m "Add task 2"
|
|
[master 82ca4b1] Add task 2
|
|
1 file changed, 1 insertion(+)
|
|
```
|
|
|
|
|
|
### My work
|
|
`git diff`
|
|
|
|
#### Result
|
|
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-practice-Mag (master)
|
|
$ git diff
|
|
warning: in the working copy of 'git-practice-Mag/todo.txt', LF will be replaced by CRLF the next time Git touches it
|
|
diff --git a/git-practice-Mag/todo.txt b/git-practice-Mag/todo.txt
|
|
index b4f858d..5a4b868 100644
|
|
--- a/git-practice-Mag/todo.txt
|
|
+++ b/git-practice-Mag/todo.txt
|
|
@@ -1,3 +1,4 @@
|
|
Task 1
|
|
Task 2
|
|
```
|
|
|
|
### My work
|
|
|
|
`git add todo.txt`
|
|
`git commit -m "New changes"`
|
|
|
|
#### Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-practice-Mag (master)
|
|
$ git commit -m "New changes"
|
|
[master dc6ae86] New changes
|
|
1 file changed, 2 insertions(+)
|
|
```
|
|
### My Work
|
|
`git log --oneline`
|
|
|
|
#### Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-practice-Mag (master)
|
|
$ git log --oneline
|
|
dc6ae86 (HEAD -> master) New changes
|
|
82ca4b1 Add task 2
|
|
b8c2503 Add new task
|
|
3a3ab4d List of tasks you need to complete
|
|
5287a29 Add first notes file
|
|
```
|
|
|
|
### My Work
|
|
`git diff dc6ae86 82ca4b1 `
|
|
#### Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-practice-Mag (master)
|
|
$ git diff dc6ae86 82ca4b1
|
|
diff --git a/git-practice-Mag/todo.txt b/git-practice-Mag/todo.txt
|
|
index 5a4b868..9d31ec7 100644
|
|
--- a/git-practice-Mag/todo.txt
|
|
+++ b/git-practice-Mag/todo.txt
|
|
@@ -1,4 +1,2 @@
|
|
Task 1
|
|
Task 2
|
|
```
|
|
### My Work
|
|
`git diff dc6ae86 5287a29`
|
|
#### Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-practice-Mag (master)
|
|
$ git diff dc6ae86 5287a29
|
|
diff --git a/git-practice-Mag/todo.txt b/git-practice-Mag/todo.txt
|
|
deleted file mode 100644
|
|
index 5a4b868..0000000
|
|
--- a/git-practice-Mag/todo.txt
|
|
+++ /dev/null
|
|
@@ -1,4 +0,0 @@
|
|
-Task 1
|
|
-Task 2
|
|
-Task 2
|
|
-Task 3
|
|
```
|
|
|
|
|
|
# 7. Creating & Switching Branches
|
|
|
|
Assignment:
|
|
|
|
Create a branch feature/feature-1:
|
|
|
|
git branch feature/feature-1
|
|
git checkout feature/feature-1
|
|
|
|
Add a line to notes.txt and commit it.
|
|
|
|
Switch back to main:
|
|
|
|
git checkout main
|
|
|
|
Observe how the file content changes.
|
|
|
|
### My Work
|
|
`git branch feature/feature-1`
|
|
`git checkout feature/feature-1`
|
|
|
|
#### Result
|
|
`Switched to branch 'feature/feature-1'`
|
|
|
|
#### Result
|
|
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~ (feature/feature-1)
|
|
$ git branch
|
|
* feature/feature-1
|
|
master
|
|
```
|
|
|
|
### My Work
|
|
```
|
|
echo "This note was made on 23rd August 2025" >> notes.txt
|
|
git add notes.txt
|
|
```
|
|
|
|
#### Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~ (feature/feature-1)
|
|
$ git status
|
|
warning: could not open directory 'Application Data/': Permission denied
|
|
warning: could not open directory 'Cookies/': Permission denied
|
|
warning: could not open directory 'Documents/My Music/': Permission denied
|
|
warning: could not open directory 'Documents/My Pictures/': Permission denied
|
|
warning: could not open directory 'Documents/My Videos/': Permission denied
|
|
warning: could not open directory 'Local Settings/': Permission denied
|
|
warning: could not open directory 'My Documents/': Permission denied
|
|
warning: could not open directory 'NetHood/': Permission denied
|
|
warning: could not open directory 'PrintHood/': Permission denied
|
|
warning: could not open directory 'Recent/': Permission denied
|
|
warning: could not open directory 'SendTo/': Permission denied
|
|
warning: could not open directory 'Start Menu/': Permission denied
|
|
warning: could not open directory 'Templates/': Permission denied
|
|
On branch feature/feature-1
|
|
Changes to be committed:
|
|
(use "git restore --staged <file>..." to unstage)
|
|
modified: notes.txt
|
|
```
|
|
|
|
### My Work - Commit
|
|
`git commit -m "New Note"`
|
|
|
|
#### Result
|
|
`Magdel@LAPTOP-NS5FVUS9 MINGW64 ~ (feature/feature-1)`
|
|
`$ git commit -m "New Note"`
|
|
`[feature/feature-1 d2ef265] New Note`
|
|
`1 file changed, 1 insertion(+)`
|
|
### My work
|
|
`git checkout master`
|
|
#### Result
|
|
`Magdel@LAPTOP-NS5FVUS9 MINGW64 ~ (feature/feature-1)`
|
|
`$ git checkout master`
|
|
`Switched to branch 'master'`
|
|
|
|
# 8. Cloning a Remote Repository
|
|
|
|
Assignment:
|
|
|
|
Go to Git Comorin and verify your repo in Git-Training-Hub exists.
|
|
|
|
Run:
|
|
|
|
git clone <your-repo-url> cloned-repo
|
|
|
|
Verify by listing files inside cloned-repo.
|
|
|
|
### My Work and Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~ (master)
|
|
$ git clone https://git.comorin.co/Git-Training-Hub/git-practice-Mag.git cloned-repo
|
|
Cloning into 'cloned-repo'...
|
|
remote: Enumerating objects: 12, done.
|
|
remote: Counting objects: 100% (12/12), done.
|
|
remote: Compressing objects: 100% (11/11), done.
|
|
remote: Total 12 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
|
|
Receiving objects: 100% (12/12), 206.16 KiB | 10.31 MiB/s, done.
|
|
Resolving deltas: 100% (2/2), done.
|
|
```
|
|
|
|
### My work
|
|
```
|
|
cd cloned-repo
|
|
ls
|
|
```
|
|
|
|
#### Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~ (master)
|
|
$ cd cloned-repo
|
|
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/cloned-repo (main)
|
|
$ ls
|
|
GIT_ASSIGNMENT.md 'repository .jpg'
|
|
```
|
|
|
|
|
|
# 9. Adding & Managing Remotes
|
|
|
|
Assignment:
|
|
|
|
In your original git-practice-<<your_name>> repo, add a remote:
|
|
|
|
git remote add origin <your-repo-url>
|
|
git remote -v
|
|
|
|
Verify the remote shows correctly.
|
|
|
|
### My work
|
|
|
|
```
|
|
git remote add origin https://git.comorin.co/Git-Training-Hub/git-practice-Mag.git
|
|
git remote -v
|
|
```
|
|
|
|
#### Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/cloned-repo (main)
|
|
$ git remote -v
|
|
origin https://git.comorin.co/Git-Training-Hub/git-practice-Mag.git (fetch)
|
|
origin https://git.comorin.co/Git-Training-Hub/git-practice-Mag.git (push)
|
|
|
|
```
|
|
|
|
# 10. Pushing & Pulling Changes
|
|
|
|
Assignment:
|
|
|
|
Push local commits to Git Comorin:
|
|
|
|
git push -u origin main
|
|
|
|
Edit a file directly on Git Comorin and commit it there.
|
|
|
|
In your local repo, run:
|
|
|
|
git pull origin main
|
|
|
|
Verify that the local file updates.
|
|
|
|
### My work
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/cloned-repo (main)
|
|
$ git push -u origin main
|
|
```
|
|
|
|
#### Result
|
|
Directed to a web page
|
|
|
|
|
|
#### My Work and Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/cloned-repo (main)
|
|
$ git pull origin main
|
|
remote: Enumerating objects: 5, done.
|
|
remote: Counting objects: 100% (5/5), done.
|
|
remote: Compressing objects: 100% (3/3), done.
|
|
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
|
|
Unpacking objects: 100% (3/3), 830 bytes | 138.00 KiB/s, done.
|
|
From https://git.comorin.co/Git-Training-Hub/git-practice-Mag
|
|
* branch main -> FETCH_HEAD
|
|
e6d6844..0d3a053 main -> origin/main
|
|
Updating e6d6844..0d3a053
|
|
Fast-forward
|
|
GIT_ASSIGNMENT.md | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
1 file changed, 61 insertions(+)
|
|
```
|
|
|
|
|
|
# 11. Ignoring Files with .gitignore
|
|
|
|
Assignment:
|
|
|
|
In your repo, create a file secret.txt.
|
|
|
|
Create .gitignore and add:
|
|
|
|
secret.txt
|
|
|
|
Run git status → confirm secret.txt is ignored.
|
|
|
|
Commit the .gitignore file.
|
|
|
|
### My work
|
|
```
|
|
echo > secret.txt
|
|
touch .gitignore
|
|
echo "secret.txt" >> .gitignore
|
|
|
|
git status
|
|
```
|
|
|
|
#### My result
|
|
```
|
|
$ git status
|
|
On branch main
|
|
Your branch is up to date with 'origin/main'.
|
|
|
|
Untracked files:
|
|
(use "git add <file>..." to include in what will be committed)
|
|
.gitignore
|
|
|
|
nothing added to commit but untracked files present (use "git add" to track)
|
|
```
|
|
|
|
### My Work
|
|
```
|
|
git add .gitignore
|
|
git commit -m "To ignore secret.txt"
|
|
```
|
|
|
|
#### My Result
|
|
```
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/cloned-repo (main)
|
|
$ git add .gitignore
|
|
warning: in the working copy of '.gitignore', LF will be replaced by CRLF the next time Git touches it
|
|
|
|
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/cloned-repo (main)
|
|
$ git commit -m "To ignore secret.txt"
|
|
[main e67a990] To ignore secret.txt
|
|
1 file changed, 1 insertion(+)
|
|
create mode 100644 .gitignore
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|