Git in Windows – Latest Installation and Usage Commands

Git is a popular version control tool used to manage code, projects, and files from the command line. It allows you to create repositories, track changes, work with branches, and connect your projects with remote repositories. Git is widely used by developers to manage their projects and keep track of changes on Windows.

Here’s what you can do with Git on Windows:

  • Create Git repositories.
  • Track changes in your projects.
  • Save different versions of your files.
  • Create and manage branches.
  • Connect local projects to remote repositories.
  • Download projects from remote repositories.
  • Upload your changes to remote repositories.
  • Check project history.
  • Work with other developers.

Install Git on Windows

You can install the latest available Git package easily using the Windows Package Manager from Command Prompt.

Open Command Prompt and run the following command:

winget install --id Git.Git -e --source winget

Wait for the installation to finish.

Once the installation is complete, close the current Command Prompt and open a new one to make Git ready to use.

Check the installed version:

git --version

You should see the installed Git version.

Git Usage Commands

After installing Git, you can start using it from Command Prompt. Below are some simple and useful Git commands for creating repositories, managing files, tracking changes, and working with remote repositories.

Set your Git username:

git config --global user.name "Your Name"

Set your Git email:

git config --global user.email "you@example.com"

Check your Git configuration:

git config --global --list

Create a new folder for your project:

mkdir my-project

Open the project folder:

cd my-project

Create a new Git repository:

git init

Check the repository status:

git status

Add a specific file to the staging area:

git add filename

Add all changed files:

git add .

Save your changes with a commit:

git commit -m "Initial commit"

View the commit history:

git log

Show a shorter commit history:

git log --oneline

Create a new branch:

git branch new-branch

List available branches:

git branch

Switch to a branch:

git switch new-branch

Create and switch to a new branch:

git switch -c new-branch

Clone a remote repository:

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

View remote repositories:

git remote -v

Add a remote repository:

git remote add origin https://github.com/user/repository.git

Push your branch to the remote repository:

git push -u origin main

Download the latest changes from a remote repository:

git pull

Fetch changes without merging them:

git fetch

Show changes that have not been committed:

git diff

Show changes between commits:

git diff HEAD~1 HEAD

Remove a file from Git tracking:

git rm filename

Rename a tracked file:

git mv oldname.txt newname.txt

Remove a branch:

git branch -d branch-name

Check the current Git version anytime with:

git --version

To see the available Git commands:

git help

For help with a specific command:

git help clone

These commands cover the most common Git tasks you may need when working with projects on Windows. You can use them to manage your files, track changes, and work with Git repositories from Command Prompt.

See also  10 Best Lightweight Linux Distros for Old Laptops and Computers

Overview

Git is a useful tool for managing projects on Windows, you can use simple commands to track changes, save your work, create branches, and connect your projects to remote repositories. It provides a simple way to manage different versions of files and keep your project work organized.

SHARE THIS POST:

Leave a Reply

Your email address will not be published. Required fields are marked *