Laravel

Git Installation: Step-by-Step Guide for Windows - Learn how to Install Git on your PC

Aug 6, 2024, 4:30 PM
Blog Thumbnail

What is Git?

Git is a distributed version control system used to track code changes in files and collaborate on software development projects like web application , mobile Application. It allows multiple developers to work on the same codebase and same time , maintain version history, and coordinate updates effectively.

Key Features of Git:

Distributed System:

Every developer has a local copy (repository) with the complete history of the project, enabling offline work.

Branching and Merging:

Git makes it easy to create branches for features, bug fixes, or experiments and merge them into the main codebase without conflicts.

Version History:

Git keeps a complete log/history of all changes, so you can revert to earlier versions or review the history of changes and find easily error solved without lossing any code .

Collaboration:

Multiple contributors can work together without overwriting each other's work using remote repositories (e.g., on GitHub or GitLab).

Staging Area:

Changes are first added to a staging area before committing, giving control over what gets included in a specific commit.

Git Commands

1. Repository Setup

git init

Initializes a new local Git repository.

git init

git clone <repo_url>

Copies your existing repository from a remote location.

git clone https://github.com/user/repo.git

2. Staging and Committing Changes

git status

Shows the status of changes (staged, unstaged, untracked).

git status

git add <file>

Adds changes to the staging area.

git add index.html

git commit -m "message"

Records a snapshot of staged changes.

git commit -m "Added new feature"

3. Branching and Merging

git branch

Lists, creates, or deletes branches.


    List: git branch
    Create: git branch feature
    Delete: git branch -d feature
        

git merge <branch>

Merges the specified branch into the current branch.

git merge feature

4. Undoing Changes

git revert <commit>

Creates a new commit that undoes the specified commit.

git revert abc123

5. Working with Remote Repositories

git remote -v

Lists remote repositories linked to the project.

git remote -v

Benefits of Git

1. Distributed Version Control

Every contributor has a local repository with the complete project history, enabling offline work. There’s no single point of failure, so if the server crashes, any local copy can restore the project.

2. Efficient Branching and Merging

Git Branches allow developers to working on new module or bug fixes. Git’s powerful merge tools resolve conflicts smoothly without helping devloper , ensuring seamless collaboration.

3. Faster Performance

Git performs fast operations like branching, merging, and committing. Commands like git status and git log run locally, making them quicker than centralized version control systems.

4. Track Changes and History

Git keeps a complete history of all changes, allowing developers to see ower commit and when. You can also revert to previous versions if needed like any error occure in code .

5. Collaboration Made Easy

Developers can use git clone, push, and pull to collaborate effectively. Git prevents overwriting with features like staging and branching.

6. Offline Capabilities

Git allows developers to commit and check logs without an internet connection, making it perfect for remote teams or limited connectivity environments.

7. Strong Security

Git uses SHA-1 hashes to ensure data integrity. Each commit is cryptographically secured, making Git a reliable choice for secure codebases.

8. Open-Source and Free

Git is open-source and free to use for all developer and organizations .

9. Interoperability with CI/CD Tools

Git integrates seamlessly with tools like Jenkins and GitHub Actions, enabling automated builds and deployments through CI/CD pipelines.

10. Custom Workflow Support

Teams can adopt workflows like GitFlow or trunk-based development, making Git flexible for various project structures.

11. Reduced Risk of Data Loss

With multiple copies of the repository, Git ensures redundancy, minimizing the risk of data loss.

12. Scalability

Git scales well for both small and large projects, supporting thousands of contributors without performance issues.

Install Git Using GitHub Desktop & Create Repository

1. Download and Install GitHub Desktop

Go to GitHub Desktop and download the installer for your operating system. Run the installer and follow the instructions given by application to install the application.

2. Sign In to GitHub Desktop

Open GitHub Desktop and sign in to your GitHub account Using mail , and login uisng google . when you have no github account when click link and create account, create one here.

3. Install Git Automatically

GitHub Desktop comes with Git pre-installed. You can verify Git installation under Options > Advanced.

4. Create a New Repository Locally

In GitHub Desktop, click File > New Repository.... Provide a name, local path, and optional description. Initialize the repository with a README.md file, and click Create Repository.

5. Commit Changes Locally

After creating the repository, add a commit message (e.g., "Initial commit"). Click Commit to main to save the changes locally.

6. Publish the Repository to GitHub (Optional)

Click Publish repository to push the repository to GitHub. Choose whether it will be public or private, then click Publish Repository.

7. Make Changes and Push to GitHub

Make changes to files in your repository using any code editor. In GitHub Desktop, you’ll see the modified files under Changes. Add a commit message, click Commit to main, and then click Push origin to sync changes with GitHub.

How to install Git on Windows 10 | Updated 2022



How to Install and Configure Git and GitHub on Windows 11