Experiment No.
2 - Explore Git and GitHub commands
Learning Objective: Students should be able to understand how to use Git and GitHub commands
Tools: MsWord, VScode, Internet Browser, Git, GitHub.
Theory:
What is Git?
Git is a Distributed Version Control System (DVCS) designed for speed, flexibility, and data integrity. It tracks
changes in a project’s files, supports branching and merging, and stores the full history of development.
Why Distributed?
Unlike centralized systems (like SVN), Git allows every developer to clone the whole repository, including its
history. This means operations like commits, diffs, and logs work locally without network access, improving
speed and reliability.
Core Concepts
Repository (repo): A directory or storage space containing all project files and their version history.
Working Directory: Your local copy of the files that you edit.
Staging Area (Index): A buffer between the working directory and the repository where changes are
prepared before committing.
Commit: A snapshot of staged changes, saved permanently with a unique SHA-1 hash and message.
Branch: A movable pointer to commits that allows parallel workstreams.
Merge: Combining two branches’ histories.
Remote: A version of your repository hosted on another server (e.g., GitHub).
Key Features and Concepts of Git
1. Version Control
Git keeps track of every change made to files in a project over time. This means:
You can revisit earlier versions of your code.
You can see what changed, when it changed, and who made the change.
You can revert to previous versions if needed.
2. Distributed System
Unlike centralized systems (like SVN), Git is distributed, meaning:
Every developer has a complete copy of the entire repository history on their local machine.
This allows for offline work and faster access to history and branches.
Changes can be shared between repositories using push and pull commands.
3. Collaboration
Multiple developers can work on the same project at the same time using branches. Each developer can:
Work independently on a branch.
Merge their branch into the main codebase once work is complete.
Use tools like git merge or git rebase to integrate changes.
4. Branches and Merging
Git encourages workflows that involve creating separate branches for different features or fixes:
Branching allows isolation of work without affecting the main code.
Merging lets you combine different branches together, resolving conflicts when changes overlap.
5. Staging Area
Git uses a staging area (also called the index) where changes are prepared before being committed:
You can choose which changes to include in a commit using git add.
Then use git commit to save those changes to the repository.
6. History and Logs
Git keeps a detailed log of all commits. You can view this with git log, which shows:
Commit IDs
Author name
Date and time of the change
Commit Message
This helps in tracking down bugs and understanding project evolution.
Why Git is Powerful
Speed: Operations like commit, merge, and branching are very fast.
Efficiency: Git handles large projects and binary files well.
Security: Git uses SHA-1 hashing to identify commits and ensure data integrity.
Flexibility: Supports various workflows (feature branches, Gitflow, trunk-based development, etc.)
Typical Git Workflow
Clone a repository: git clone
Create a branch: git checkout -b new-feature
Make changes and stage them: git add .
Commit changes: git commit -m "Added new feature"
Push branch to remote: git push origin new-feature
Merge branch via pull request or locally: git merge
Basic Git Commands:
git init: Initializes a new Git repository.
git clone <url>: Clones a repository from a remote server.
git add <file>: Stages changes for commit.
git commit -m "message": Commits staged changes with a message.
git status: Displays the status of changes.
git branch: Lists, creates, or deletes branches.
git merge <branch>: Merges changes from one branch into another.
git pull: Fetches and merges changes from a remote repository.
git push: Pushes local changes to a remote repository.
GitHub: GitHub is a web-based platform that provides hosting for Git repositories. It adds several features
on top of Git to facilitate collaboration and project management.
Basic GitHub Actions:
● Fork: Create a personal copy of a repository.
● Pull Request: Propose changes to a repository and request that they be merged.
● Issue: Report bugs or request new features.
● GitHub Actions: Automate workflows like testing and deployment.
Viva Questions:
1. What command initializes a new Git repository?
2. How do you stage a file for commit in Git?
3. Which command do you use to check the status of changes in your Git repository?
4. How do you switch to a different branch in Git?
5. What command pushes local changes to a remote GitHub repository?
Conclusion:
_________________________________________________________________________________________
_________________________________________________________________________________________
_________________________________________________________________________________________
_________________________________________________________________________________________
_________________________________________________________________________________________
For Faculty Use
Correction Formative Timely Attendance /
Parameter Assessment Completion of Learning
[40%] Experiment Attitude
[40%] [20%]
Marks
Obtained