What is Git?
Git is a free, open-source, distributed version control system used to manage and track changes in source code or data across software projects of any size - from small repositories to very large enterprise systems. It helps developers collaborate efficiently by maintaining a complete history of code changes, allowing multiple people to work on the same project simultaneously without conflict.
Why Version Control?
Version control systems (VCS) are essential tools for modern software development. They help track, manage, and synchronize changes made by multiple contributors, ensuring data integrity and traceability.
Key Benefits
• Tracks all changes: Every modification to a file is recorded, allowing you to view, revert, or compare previous versions at any time.
• Eliminates file duplication: version control maintains a single authoritative version of each file.
• Maintains complete history: Each file's full evolution can be audited, making it easy to understand what changed, when, and by whom.
• Facilitates teamwork: Developers can work on separate features or fixes in isolated branches without interfering with others.
Basic Git Concepts
Working Directory: The workspace on your computer where you make changes to project files. Git doesn't track these changes until you explicitly stage them.
Staging Area (Index): A temporary area where you prepare and organize changes before committing. It acts as a 'draft' zone.
Local Repository: Your personal copy of the project's complete history stored on your local machine. It includes all commits, branches, and tags.
Remote Repository: A version of the project stored on a server (e.g., GitHub, GitLab). It enables collaboration by allowing users to push and pull changes.
Branches: Independent lines of development used to create new features or fix bugs without affecting the main codebase.
Pull Request (PR): A formal proposal to merge changes from one branch into another, usually reviewed and discussed by team members.
Merge: The process of integrating changes from one branch into another, combining their histories.
Installing Git
On Windows:
Download the official Git installer from https://git-scm.com/downloads .
![Git 1]()
Run the installer and follow the setup wizard.
Accept default settings and ensure the default branch name is set to main (recommended).
Complete installation and verify by running git --version in the terminal.
![Git 2]()
Configuring Git
After installation, configure your user identity to associate commits with your name and email:
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
![Git 3]()
To view all configuration settings:
git config –list
![Git 4]()
Basic Terminal and Git Commands
Creating a New Folder and Navigating:
mkdir Git_Sample
cd Git_Sample
![Git 5]()
To open the folder in VS Code. Use
code .
![Git 6]()
Creating a File:
touch hello.md
(.md - markdown is a lightweight markup language for creating formatted text using a plain text editor. It was designed to be easy to read and write in its source form, and then easily converted to structurally valid HTML or other formats)
![Git 7]()
Checking Repository Status:
git status
![Git 8]()
Git is not initialized now.
To Initializing a Repository:
git init
![Git 9]()
This allows git to start tracking our project.
Check git status now,
![Git 10]()
Then we can see that Git is tracking the project and prompts us to add the hello.md file to the staging area.
Staging Changes:
git add .
![git 11]()
This command will add all the changes from the working directory to the staging area.If you then run git status, you’ll notice that the color of the file name has changed, indicating that the file is now staged and ready to be committed.
Next, open VS Code and edit the hello.md file. For example, add the following line: # I am learning to use Git!
Save the file, then go back to Git Bash and run the following command to check the file status again:
git status
![Git 12]()
Then run git add . to add the changes to the staging area. After that, run touch newfile.js to create a new file.
Then run git status to check the current state of the repository.
![Git 13]()
In this image, one file is green and another is red. This means the hello.md file is staged, while newfile.js is unstaged .
Committing Changes:
git commit -m "Initial commit"
This command allows us to saves our changes with the message attached to it.
![Git 14]()
Next, run git status . It will show the new file in red, indicating it is unstaged . Then execute git add . followed by git commit -m "New File Added" . After this, Git will start tracking the new file.
Then run git status to check the current state of the repository.
![Git 15]()
Git vs GitHub
Git: A local version control system that manages code history and tracks changes on your computer.
GitHub: A cloud-based hosting platform for Git repositories, enabling collaboration, issue tracking, and code review.
Together, Git and GitHub streamline teamwork and make code sharing, reviewing, and version management seamless.
Summary
Git helps developers track and manage changes to source code efficiently.
Basic workflow: Make changes → Stage changes → Commit changes.
Proper configuration ensures accurate author information for each commit.
Branches and remote repositories simplify teamwork and code management.
Git and GitHub empower teams with powerful collaboration and automation tools.
Next: Mastering Essential Git Commands - https://www.c-sharpcorner.com/article/mastering-essential-git-commands/