Git Bash Windows

Posted on by
Git Bash Windows Average ratng: 3,5/5 7058 votes

By default, Git is installed on Linux and macOS computers as a command line option. However, Microsoft Windows does not include a Git command. Below are the steps on how to install and use Git and GitHub on Microsoft Windows.

Other Git for Windows downloads Git for Windows Setup. 32-bit Git for Windows Setup. 64-bit Git for Windows Setup. Git for Windows Portable ('thumbdrive edition') 32-bit Git for Windows Portable. 64-bit Git for Windows Portable. The current source code release is version 2.23.0. If you want the newer version, you can build it from the source code. How to add more to Git Bash on Windows. Git for Windows comes bundled with the 'Git Bash' terminal which is incredibly handy for unix-like commands on a windows machine. It is missing a few standard linux utilities, but it is easy to add ones that have a windows binary available.

Installing Git on Windows

  1. Click the Download link to download Git. The download should automatically start.
  2. Once downloaded, start the installation from the browser or the download folder.
  3. In the Select Components window, leave all default options checked and check any other additional components you want installed.
  4. Next, in the Choosing the default editor, used by Git unless you're familiar with Vim we highly recommend using a text editor you're comfortable using. If Notepad++ is installed, we suggest using it as your editor. If Notepad++ is not installed, you can cancel the install and install Notepad++ and then restart the GitHub install.
  5. Next, in the Adjusting your PATH environment, we recommend keeping the default Use Git from the command line and also from 3rd-party software as shown below. This option will allow you to use Git from either Git Bash or the Windows Command Prompt.
  1. Next in the, we recommend leaving the default selected as Use OpenSSH.
  2. Next, in Choosing HTTPS transport backend, leave the default Use the OpenSSL library selected.
  3. In the Configuring the line ending conversions, select Checkout Windows-style, commit Unix-style line endings unless you need other line endings for your work.
  4. In the Configuring the terminal emulator to use with Git Bash window, select Use MinTTY (the default terminal of MSYS2).
  5. On the Configuring extra options window, leave the default options checked unless you need symbolic links.
  6. Click the Install button
  7. Once completed, you can check the option to Launch Git Bash if you want to open a Bash command line or, if you selected the Windows command line, run Git from the Windows command line.
Tip

We highly recommend you use Git from the command line and not use a GUI interface. You'll only be using the command line to interface with Git to manage the files. Editing can still be done through a text editor or IDE of your choice. If you're new to the command line, you can find help with navigating the Windows command line and Linux (Bash) through the links below.

Configuring and connecting to a remote repository

In our example, we will be using GitHub as a storage for our remote repository. Below are the steps on how you can connect to a GitHub repository. If you are new to GitHub, you can follow our steps on how to create a new GitHub repository if you need additional help.

  1. From the command line, move to the directory you want to contain your Git repository.
  2. Type the following command to configure your Git username, where <your name> will be your GitHub username.
  1. After entering the above command, you should be returned to the command prompt. Next, enter your e-mail address by typing the following command, where <your e-mail> is your e-mail address.
  1. Once the above steps have been completed, you'll be ready to connect to a remote repository. To find the repository address, go to a repository on GitHub and click the Clone or download repository link to get the address. For example, we've created a repository called 'example' that can be found at the https://github.com/Computerhope/example.git address. Copy the address to your clipboard.
  2. Once copied go back to the command line and type the following command, where <URL> is the address you copied. To paste that address into the command line right-click in the command line window and click paste.
  1. Once the Git repository is created, you'll have a new directory in your current directory with the name of the Git repository.
  2. Once the Git remote repository is cloned to your local repository, you should have a new folder in the current directory with the name of the Git repository. For example, in our 'example' Git we would have a new directory called 'example'. Use the cd command to change into the new directory.
  3. Once in the new directory, type the following command to list the remote repositories.
  1. If successful, you should see 'origin' that is the name of your master Git branch. To see the aliases (URL or path), type the following command.

Running each of the above commands give you an output similar to what is shown in our example below.

Now that you've connected to a remote repository on GitHub you're ready to start working on the files and pushing and pulling files as you update the files.

Working in your local repository and pushing files

After following the above steps and cloning a remote repository, you can work on the files as you normally would. You can create new files or edit existing files from the command line or your favorite text editor. Below we will go through the steps in creating a new file and pushing that new file as well as editing an existing file and pushing the update.

Creating a new file and pushing to remote repository

Git Bash Download Windows 10

  1. Create a new file in the Git directory by typing the following command from either the Bash or Windows command line. The following command will open and create a file called example.txt in Notepad. In Git Bash, you could also use the touch command to create a blank new file and then type 'start <name of file>' to open the file in your favorite text editor.
  1. In the text editor, enter some text into the file and save and exit the file.
  2. Back at the command line type the following command to get the current status of your branch and untracked files.
  1. Git displays a window similar to the example shown below, showing that the file we created is new and untracked by Git.
  1. As mentioned in the notes and seen in the picture, we'll now want to add this file to Git to be tracked by typing the following command. If your file is not named 'example.txt,' you'd want to change the text to the name of your file.
  1. After entering the above command, the file will be added as a new file also known as staging. Typing git status again shows you in green that the file is a new file that is ready to be committed.
  2. Next, type the following command to commit the changes made in the local workspace to the local repository. In the example below, our notes 'First example' should be notes that will make sense to you and anyone else who may be working with you on your project.
Note

You can also type git commit with no additional tags or options. However, when doing this it will open a vim like editor that can be difficult for those not familiar with the vim to use. If you type this command press 'i' to enter insert mode and type the notes for the commit on the first line, press Esc, and then type ':wq' to save, exit, and commit. We suggest using the above command because it's easier for more people to use.

  1. Finally, now that changes have been moved from your workspace into your local repository it is ready to be pushed to the remote repository. Type the following command to push all changes to the remote repository.
Tip

If you want to follow the progress, you can type git status again to see the current status. You can also type git log to see a log of changes.

Note

You'll be asked for your GitHub username and password if your computer has not logged into Git from the command line.

Once the file is pushed, it will appear in your GitHub remote repository and will also be available to everyone else who're working with the same repository.

Modifying a file and pushing to remote repository

  1. Edit and modify one or more files in your Git.
  2. Type git status to get see the status of all the files that have not yet been committed from the workspace to the local repository.
  3. Type the following command to add all files. The single period indicates that you want all files to be added to the local repository. Some people may also use git add -A to add all.
Tip

You can also use wildcards instead of a period. For example, if you wanted to add all text files you could type *.txt instead of a single period to only add text files.

  1. Once the files have been added, type the following command to commit. Change the notes to apply to your commit.
  1. Finally, type git push to push the commit to the remote repository.
Tip

If you're working with a lot of other people, we'd recommend that you pull (explained below) before committing. If your local repository is not the same as the remote repository (excluding your new changes), the commit will fail. For example, if someone has added new files to the remote repository while you've been working and you try commiting it will fail until you pull.

Pulling or fetching updates from the remote repository

If it's been awhile since you've committed any work, perform the git pull command to get the latest updates from the remote repository and merge them into your local repository. By pulling all of the updates from a repository before commiting, you can make sure your local repository and the remote repository are the same to help prevent merge conflicts.

To get all changes without merging, run the git fetch command to grab all of the latest updates from the remote repository without merging any of the new changes.

How to deal with a Git merge conflict

When multiple people are working with the same files, you're going to encounter merge conflicts. When a conflict occurs, Git will modify your local files and it is up to you to manually fix the files with the conflicts.

Tip

Use the git status command to see the status and merge conflict information.

Open the file with the conflict to start correcting the errors. In the example file below, we had a text file with one line of text and in the local repository we added the text 'update1' to the file. However, during the same time, the remote repository file was modified and added 'update2' to the file on the same line. Git marks conflicts with '<<<<<<< HEAD' for lines in the current branch and everything after ' as the remote changes followed by '>>>>>>> < hash >' to represent the end of the conflict.

To resolve this merge conflict, we would need to decide what text we wanted to keep, update, or remove. In this example, we want to keep 'update1' and 'update2' in the order they're listed so we would only need to remove the Git markings to make the file resemble the following example.

Note

If you're working with a big file, it's a good idea to search the file for 'HEAD' because it is possible that there may be more than one conflict.

Once the changes are made in the file, we could save the file and then perform the following git commands to update the fixes.

The example given in this merge conflict is a very basic example. When dealing with a file that has more than a few lines of text or has big sections of code conflicting dealing with a merge conflict can get a lot more confusing. To make it easier to deal with merge conflicts, you can use the command git mergetool to use a merge tool, such as WinMerge or another popular merge tool.

Creating a Git branch

Git Bash Windows Authentication Failed

Creating a branch allows you to create a duplicate of the master (trunk) and make several updates without affecting the master. For example, if you were developing a program and needed to work on fixing a bug that could take weeks or months to fix, you could create a branch of the master to work on fixes. Once you've fixed the bug, you could merge your branch back into the master.

To create a branch in your local repository, follow the steps below.

  1. In the Git master directory, type the following command, where '<New Branch>' is where you would put the name of the new branch name. For example, we could call the branch 'examplebranch'.
  1. Next, type the following command to switch to the branch.
  1. After entering the above command, the prompt (in Git Bash) will change from 'master' to the name of the branch as an indication that you're working in a branch and not the master.
  2. From this point, you can continue to use Git and modify the files how you have in the past.
  3. To see all available branches, you can use the git branch command. For example, typing git branch displays your local repository branches. Typing git branch -a displays all local and remote repositories.
  4. If you need to push the branch to the remote repository, you can run the following command.
  1. Finally, if you need to switch back to the master branch, you can type the following command.

How to merge a branch back into the master

After you've completed your work in a branch, you'll want to merge it back into the master or another branch by following the steps below.

  1. Move into the branch you want to merge into. For example, if you wanted to merge back into the master, type the following command.
  1. Once in the master, type the following command to merge the branch.
  1. Once the merge is performed, add the files.
  2. Next, commit the changes.
  3. Once merged and committed, push the merge by typing the following command. If you get conflicts during the merge, see our how to deal with merge conflicts section.

How to delete a local and remote branch

If after merging a branch you no longer want to keep the local or remote branch, you can perform the following commands.

Git Bash Windows Bash_profile

To delete the local branch, type the following command.

To delete the remote branch, type the following command.

Additional information

  • See our revision control and GitHub pages for further information and related links.
Active4 months ago

I just upgraded to Git 1.8.0.1 for Windows, from my previous version 1.7.9.mysysgit.0. I downloaded the new version from the Git site and installed through the normal Git installer EXE.

That said, when I fire up my terminal window, it still is showing that I am running git version 1.7.9.mysysgit.0. When I type 'git --version' from my prompt, same thing.

I found this article on a similar issue with Git on Mac OSX, which leads me to believe that it has something to do with a faulty PATH, but I'm still pretty new at all this (5 months self-taught), so I'm at a loss in how to translate this to Windows.

This problem arose when I began a new Rails project and tried to push it up to Git. I added the remote:

then:

I received the following error message:

Kensington mouse driver download. fatal: https://github.com refs not found: did you run git update-server-info on the server?Download free microsoft dvd player.

Googling that error led me to this article, which prompted me to upgrade, and here I am.

Community
BrianScottKBrianScottK
1,2442 gold badges9 silver badges7 bronze badges

7 Answers

Since Git 2.16.1(2) you can use

In versions between 2.14.2 and 2.16.1, the command was

(It was later renamed to avoid confusion with updating the local repository, e.g. like svn update does it.)

That command does not exist in Git 2.13 and before.

If this errors with 'is not a git command' then either you don't actually have Git for Windows, or your version is very old.

In which case, simply get the latest installer from https://git-scm.com/download (check whether you want 32- or 64-bit) and run it to upgrade.

If you already have the latest version it does nothing, in which case you can manually run the installer to reinstall.

Dutch GloryDutch Glory
4,5371 gold badge10 silver badges5 bronze badges

Update (26SEP2016): It is no longer needed to uninstall your previous version of git to upgraded it to the latest; the installer package found at git win download site takes care of all. Just follow the prompts. For additional information follow instructions at installing and upgrading git.

DavidDavid

Git Bash Windows Tutorial

First, check your git version by using this command

Then follow the case according to your git version

Three cases :

  1. If your git version is less then 2.14.1.

    Uninstall the git download the latest git and install it again.

  2. And versions between 2.14.2 and 2.16.1

    Use command git update

  3. version is equal to greater Git 2.16.1(2)

    Use command git update-git-for-windows

Arslan AhmadArslan Ahmad

Using the command 'where git' find out how command prompt picks up the version. Once you have the path, you can go ahead and uninstall / delete previous version completely. Then if you install and make sure the new installed location is in the path, it should just work fine.

Using git-friendly tools like cmder will make your life much easier. You don't really have to use dual boot or cygwin anymore since the support for git in windows is already top-notch now. (Git for windows installs msysgit which includes all necessary unix tools from MinGW. MinGW has been there for a while and is pretty stable. If you want you can install the full version of msysgit rather than Git for Windows. msysgit is available on Git for windows page at the bottom.)

Rajan PonnappanRajan Ponnappan

Based on the last response from @Simon, I first uninstalled the new version of Git. I then re-installed the new version of Git into the same directory as the old version, C:/RailsInstaller/Git, instead of the default directory C:/Git.

Now my rails terminal window shows that I am running the new git version 1.8.0.

BrianScottKBrianScottK
1,2442 gold badges9 silver badges7 bronze badges

to check out your PATH variable, act as follow:

  1. From the Desktop, right-click My Computer and click Properties.
  2. Click Advanced System Settings link in the left column.
  3. In the System Properties window click the Environment Variables button.

Once there, scroll to get the Path row, you'll get a long string of paths (e.g. C:windowsbin;C:program filesgit, etc)

Git Bash

Find the line or lines where git is referenced. Then, make sure this path point to your Git 1.8.x installation. If not, delete it and add the real path to the newest Git version. At the end, you should only have one path in the string linking to Git.

Hope this help!

Simon BoudriasSimon Boudrias
31.3k10 gold badges77 silver badges115 bronze badges

I don't think your problem is related to Windows global PATH, as remote is specific to repo.

I recommend you to use Git under Cygwin. Git could work under Windows command line, but there may be some weird problems hard to figure out. Under Cygwin it's more nature and has less error.

All you need is to type bash in Window CMD then start to use the Unix tools and commands. You can use a shortcut to load bash, it's as easy as use normal Windows CMD.

The same is true for Rails and Ruby. I used RailsInstaller before, but found using Cygwin to install Rails is more stable.

Finally I'll suggest to install Ubuntu dual boot if you have time(about a month to get familiar). Windows is not very friendly to every Unix tools ultimately. You'll find all pain stopped.

Billy Chan

Git Bash Windows Add Ssh Key

Billy Chan

Git Bash Windows Download

22.2k4 gold badges45 silver badges62 bronze badges

Not the answer you're looking for? Browse other questions tagged windowsgitupgrade or ask your own question.