SkyShelf

Guides

How to Install Git on Windows and Make Your First Repository

How to Install Git on Windows and Make Your First Repository

Git is the version control system behind most modern software projects, and it is just as useful for notes, scripts, website files or any folder of text you want to keep a history of. On Windows, the usual way to get it is Git for Windows, a project that packages Git together with a Bash shell and a few conveniences. This guide walks through installing it, telling Git who you are, and making your first repository with a couple of commits.

What you get with Git for Windows

According to the project's own website, Git for Windows bundles several pieces:

  • Git Bash, a Bash emulation for running Git from the command line with the same commands you will see in most tutorials.
  • Git GUI, a graphical front end covering most Git functions, including visual diffs.
  • Shell integration, so you can right-click a folder in File Explorer and open Git Bash or Git GUI there.
  • Git Credential Manager, which stores credentials securely for hosting services such as GitHub and Azure Repos.

You do not have to use all of it. Many people install it once and then work entirely from Windows Terminal or from the built-in source control panel in Visual Studio Code.

Step 1: Install Git

  1. Download the installer from the official Git for Windows site (gitforwindows.org) or from git-scm.com. Avoid third-party mirrors that wrap installers in download managers.
  2. Run the installer and step through the option pages. The defaults are a sensible starting point for a first install. Two choices are worth reading carefully: which text editor Git should open when it needs a commit message, and how the command-line environment should be set up.
  3. Finish the wizard, then open the Start menu and launch Git Bash.

To confirm the install worked, type this and press Enter:

git --version

If Git prints a version number, you are ready.

Step 2: Tell Git who you are

Every commit records an author, so Git asks you to set a name and an email address once. The official Pro Git book gives these commands:

git config --global user.name "Your Name" git config --global user.email "your-email-address"

The --global flag stores the values for your Windows user account, so you only do this once. If you later host code publicly, remember that the email you configure will be visible in your commit history.

Two optional settings are worth knowing about:

  • git config --global init.defaultBranch main makes new repositories start on a branch called main instead of Git's historical default.
  • git config --global core.editor ... chooses the editor for commit messages. On Windows you generally need to give the full path to the editor's executable, and the book warns that skipping a proper editor setup can leave you in a confusing state when Git tries to launch one.

You can review everything Git knows with git config --list.

Step 3: Create your first repository

Create a folder for a practice project and move into it. In Git Bash:

mkdir my-first-repo cd my-first-repo git init

git init creates a hidden .git folder, which is where Git keeps the history. Nothing is tracked yet.

Now add a file. Create README.md in your editor with a line or two of text, save it in the folder, and run:

git status

Git reports the file under Untracked files, meaning it exists in the folder but is not part of any snapshot yet.

Step 4: Stage and commit

Git uses a two-step flow. You first stage the changes you want, then commit them as one snapshot.

git add README.md git status git commit -m "Add README"

After git add, git status lists the file under Changes to be committed. The -m option on git commit supplies the message inline so no editor opens. Write messages that say what changed and why, in a short sentence.

Edit the file again, then repeat the cycle: git status, git add, git commit -m "...". To see your history, run git log, which lists commits with the newest first. Adding --oneline gives a compact one-line-per-commit view.

Step 5: Clone an existing project

You will often start from someone else's repository instead of an empty folder. The command is git clone followed by the address of the repository, and an optional folder name:

git clone <repository-address> my-copy

Cloning downloads the full history and sets up a connection back to the original, which you will use later when you pull updates or push your own work.

Common problems

"git is not recognized." Close and reopen the terminal after installing, because open windows do not see the updated search path. If it still fails, rerun the installer and check the option that controls how Git is exposed to the command line.

Git opens an editor you do not know how to use. That is the commit-message editor. Save and close it to finish the commit, or run commits with -m until you have configured an editor you like.

Your commit shows the wrong name. Re-run the two git config --global commands. Past commits keep their old author; the change applies to new ones.

You do not want certain files tracked. List patterns for build output, logs or secrets in a file named .gitignore in the project root, and Git will leave matching files out of git status.

Where to go next

Once the basics feel natural, learn branching, merging and working with a remote repository. The free Pro Git book on git-scm.com covers all of it, and the commands you used here are the foundation for everything else. For editing and reviewing changes, a code editor with Git built in, such as Visual Studio Code, makes the stage-and-commit cycle visual while still using the same underlying commands.

Comments

No comments yet.

Code