How to Get Started with Git Bash on Windows
Boost your career with the AWS Certified Solutions Architect certification. Get a FREE prep guide: deep dive into exam domains, preparation tips, and valuable resources. Download.
Did you know you can access Linux utilities directly on your Windows operating system? Perhaps you’re looking for a separate terminal to run Git and Linux commands. If so, give it a shot to learn about Git Bash (Bourne Again Shell).
Not a reader? Watch this related video tutorial!
In this tutorial, you’ll learn what Git Bash is, install it on Windows, and run some basic commands on Git Bash terminal.
Prerequisites
The demonstrations in this tutorial are on a Windows 10 PC version 1909, but any other version (7-8.1) of Windows PC will work.
What is Git Bash?
Before you look at what Git Bash is, let’s go over what Git is. Git is a version control system for controlling changes in software development. Like macOS and Linux, operating systems already have a command-line terminal where you can run Git and Linux commands directly. But for Windows, you have the Windows command prompt, which is a non-Unix terminal.
How can you run Git and Linux commands in Windows? Git Bash will do the trick. Git Bash is an emulator that provides an emulation layer for Git to run Linux commands on Windows PCs. An emulator enables one specific system to behave like another computer system.
Downloading and Installing Git (Bash)
Now that you know a little about Git Bash let’s see how you can download and install it. There are three different ways of downloading the Git software for Windows OS, as shown below.
- Through Git’s official website
- Through a separate project on GitHub called Git for Windows.
- Through a software package manager like Chocolatey
Download Git with any of the three ways you prefer, but this tutorial will use the official website.
After downloading Git, let’s start installing it on your Windows PC.
Launch the installer you downloaded and click Next through the steps until you get to the Select Components screen.
Now, check the boxes of additional components you want to include in the installation. Leave the ones selected by default, as shown below, and click Next.
Leave the default for creating a shortcut in the start menu folder, and click Next.
Select Use Notepad as Git’s default editor from the drop-down list as a default editor to use with Git, and click Next. Now Git files like ~./gitconfig will open in Notepad by default.
Select the Override the default branch name for new repositories option as the default branch name (main) for Git to use. When you initialize a Git repository, Git will use this branch name by default.
The default branch name used to be “master” for Git repositories. But many people found “master” an offensive word. So GitHub followed the Software Freedom Conservancy’s suggestion and provided an option to override the default branch name when initializing a Git repository.
Now, select Git from the command line and also from 3rd-party software option so that Git command can be executed from different tools. Some of those tools are Command Prompt, PowerShell or any other 3rd party software tools, along with the Git Bash console.
Select the Use the OpenSSL library option to let Git validate certificates with OpenSSL, and click Next. OpenSSL is a cryptographic library that contains open-source implementation of SSL and TLS protocols.
If you are using Git in an organization with enterprise-managed certificates, select the User the native Windows Secure Channel library option instead.
Leave the default Checkout Windows-style, commit Unix-style line endings option selected, and click Next.
If you configure “Windows-style” line ending conversions, when you hit return on your keyboard after executing a Git command, Git will insert an invisible character called line ending. When different contributors make changes from different operating systems, Git might produce unexpected results.
Select the Use Mintty (the default terminal of MSYS2) option as the default terminal emulator to run commands, and click Next. Mintty is the default terminal of MSYS2. MSYS2 is a collection of tools and libraries that provides a Unix-like environment for software distribution and a building platform for Windows.
Select the Default (fast-forward or merge) option below as git pull command’s default behavior. The git pull command is the shorthand for git fetch and git merge. which fetches and incorporates changes from a remote repository into the current branch.
Perhaps you want to merge a new branch to the master. If so, Git would directly merge using fast-forward without going through git fetch and git merge commands. The merge is only possible if there are no commits on master from when you’ve created the new branch.
Select the Git Credential Manager Core as the default Git credential helper, and click Next. Git credential helpers are external programs that Git can prompt for input data, like usernames and passwords. These input data can be stored in memory for a limited time or stored on the disk.
Git Credential Manager Core is based on the.NET framework and will provide multi-factor HTTPS authentication with Git.
Leave the extra features on default, as shown below, and click Next. The Enable file system caching option is checked to provide quick results when executing Git commands.
Ensure to leave both options below at default (pseudo console and built-in file system monitor) as they are still in an experimental stage, and click Install.

Finally, right-click on your desktop and select Git Bash Here from the context menu, as shown below, to launch Git Bash terminal. Launching Git Bash from your desktop is one of the quickest ways to do so, but the same process goes when you right-click on a folder.
Run the git command below to verify Git Bash is installed and its current version (.-version ).
You can see below the current Git version in this tutorial is version 2.32.0.Windows.2.
Running Git Commands in Different Terminals
Now that you have Git Bash on your PC, it’s time to learn some Git commands. Running Git commands isn’t limited to Git Bash console only. Did you know you can run Git commands in the command prompt too? Yes!
Let’s run Git commands both on Git Bash console and command prompt to declare variables accessible in both terminals.
Launch Git Bash console by clicking on the Start button, type git, and click on Git Bash.
Run the below git config command to add your name ( YourName ) as your git username ( user.name ). The git config command administers configuration variables that control how Git looks and operates.
Pass the.-global option to the git config command to define the configuration variable ( YourName ) in the ~/.gitconfig file specifically.
git config.-global user.name “YourName”
Now open the command prompt and run the below git config command to add your email ( “[email protected]” ) as your git user email (.-global user.email ) in the ~/.gitconfig file.
In the same command prompt window, run the below git config command to list (.-list ) all the configuration variables in Git.
You can see below that even though you’ve added variables in the ~/.gitconfig file via different consoles, the variables are accessible and displayed in the command prompt.
Running Linux Commands in Git Bash
As you can tell, all Git commands work in both Git Bash and the command prompt. And since Git is delivered as a Unix-style command-line environment, let’s try running a Linux command on the Git Bash console!
Run the ls command both in Git Bash console and command prompt to list the files and folders in the working directory.
In the screenshots below, you can see that the Git Bash console returns an output, while the command prompt throws an error, saying the ‘ls’ command is not recognized.
You can run Linux commands on the command prompt so long as you change the directory to C:\Program Files\Git\usr\bin first.
In the command prompt, run the commands below to change the working directory to C:\Program Files\Git\usr\bin and run the ls command.
cd C:\Program Files\Git\usr\bin # Change directory to where Linux utilities are stored ls # Linux command that lists all files and folders in the working directory
Below, you can see that you didn’t get an error after running the ls command this time, but the command returned results instead.
Conclusion
This tutorial aims to explain what Git Bash is and the steps for Git software installation. You’ve learned what Git Bash is and that running Git commands both on Git Bash and command prompt is possible.
Next time when you have to run Git commands, which console would turn to?
Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.
.5 Getting Started. Installing Git
Before you start using Git, you have to make it available on your computer. Even if it’s already installed, it’s probably a good idea to update to the latest version. You can either install it as a package or via another installer, or download the source code and compile it yourself.
This book was written using Git version 2. Since Git is quite excellent at preserving backwards compatibility, any recent version should work just fine. Though most of the commands we use should work even in ancient versions of Git, some of them might not or might act slightly differently.
Installing on Linux
If you want to install the basic Git tools on Linux via a binary installer, you can generally do so through the package management tool that comes with your distribution. If you’re on Fedora (or any closely-related RPM-based distribution, such as RHEL or CentOS), you can use dnf :
If you’re on a Debian-based distribution, such as Ubuntu, try apt :
For more options, there are instructions for installing on several different Unix distributions on the Git website, at https://git-scm.com/download/linux.
Installing on macOS
There are several ways to install Git on macOS. The easiest is probably to install the Xcode Command Line Tools. On Mavericks (10.9) or above you can do this simply by trying to run git from the Terminal the very first time.
If you don’t have it installed already, it will prompt you to install it.
If you want a more up to date version, you can also install it via a binary installer. A macOS Git installer is maintained and available for download at the Git website, at https://git-scm.com/download/mac.
Installing on Windows
There are also a few ways to install Git on Windows. The most official build is available for download on the Git website. Just go to https://git-scm.com/download/win and the download will start automatically. Note that this is a project called Git for Windows, which is separate from Git itself; for more information on it, go to https://gitforwindows.org.
Getting started with Git in Visual Studio
To get an automated installation you can use the Git Chocolatey package. Note that the Chocolatey package is community maintained.
Installing from Source
Some people may instead find it useful to install Git from source, because you’ll get the most recent version. The binary installers tend to be a bit behind, though as Git has matured in recent years, this has made less of a difference.
If you do want to install Git from source, you need to have the following libraries that Git depends on: autotools, curl, zlib, openssl, expat, and libiconv. For example, if you’re on a system that has dnf (such as Fedora) or apt-get (such as a Debian-based system), you can use one of these commands to install the minimal dependencies for compiling and installing the Git binaries:
sudo dnf install dh-autoreconf curl-devel expat-devel gettext-devel \ openssl-devel perl-devel zlib-devel sudo apt-get install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev \ gettext libz-dev libssl-dev
In order to be able to add the documentation in various formats (doc, html, info), these additional dependencies are required:
sudo dnf install asciidoc xmlto docbook2X sudo apt-get install asciidoc xmlto docbook2x
Users of RHEL and RHEL-derivatives like CentOS and Scientific Linux will have to enable the EPEL repository to download the docbook2X package.
If you’re using a Debian-based distribution (Debian/Ubuntu/Ubuntu-derivatives), you also need the install-info package:
sudo apt-get install install-info
If you’re using a RPM-based distribution (Fedora/RHEL/RHEL-derivatives), you also need the getopt package (which is already installed on a Debian-based distro):
Additionally, if you’re using Fedora/RHEL/RHEL-derivatives, you need to do this:
sudo ln.s /usr/bin/db2x_docbook2texi /usr/bin/docbook2x-texi
due to binary name differences.
When you have all the necessary dependencies, you can go ahead and grab the latest tagged release tarball from several places. You can get it via the kernel.org site, at https://www.kernel.org/pub/software/scm/git, or the mirror on the GitHub website, at https://github.com/git/git/tags. It’s generally a little clearer what the latest version is on the GitHub page, but the kernel.org page also has release signatures if you want to verify your download.
tar.zxf git-2.8.0.tar.gz cd git-2.8.0 make configure /configure.-prefix=/usr make all doc info sudo make install install-doc install-html install-info
After this is done, you can also get Git via Git itself for updates:
git clone https://git.kernel.org/pub/scm/git/git.git
Best Git GUI Clients for Windows
The importance of Rapid but at the same time, efficient software development can not be overestimated. It is the standard of high professionalism that is an absolute must for every successful company. It also means the ability to embrace and implement innovations really quickly. And Git is one of the effective ways to keep up with constantly changing requirements.
Git is a Version Control System (VCS) designed to track and record all changes made to files and code. With its help, you can compare, analyze, and merge changes, commit them to the repository (the storage of your code and code changes), or roll them back and restore the previous versions.
You won’t need to worry about making a mistake or losing code. Or, more precisely, of course, you will worry because you are a professional who cares about quality. But if an error happens – you can fix everything immediately.
Git is not the only VCS, but it is, undoubtedly, the most popular one. Since its birth in 2005, it has become the default solution for version control – decentralized, simple, fast, and highly efficient. All developers have the same tools, and the entire development process is much more flexible and transparent.
To work with Git, you can use the functional command-line interface. Git professionals consider this to be the right way. On the other hand, as an alternative, you can use a Git GUI.
The Git GUI client is a tool that allows the developer to work with this version control system in a visual mode. It does not require writing commands manually, offering a convenient graphical interface with the in-built options. This way, one can perform the tasks faster and in a more comfortable manner.
In this article, we are going to review the most popular Git GUI tools for Windows to determine their strong sides and help you pick the right solution for your routines.
Top 10 Git GUI clients
Modern technologies brought us a lot of software solutions to work with Git. Some developers, who aren’t satisfied with any of the currently existing Git GUI clients, even start to create their own tools. That’s why the variety of available Git client software is already impressive.
In our review, we’ll FOCUS on Git GUI tools for Windows, as this OS remains the leading one, occupying almost 73% of the market. We are going to consider the clients developed for Windows OS or cross-platform tools that work on Windows.
Our Git desktop client Top 10:
If you are into Git, you might have already used some particular Git desktop client. Or, at least, heard of some of them. So, let us dive deeper and see what these tools can offer to the developers.
GitHub Desktop
GitHub Desktop is, perhaps, the most famous solution for working with Git in a visual interface. It is familiar to all developers keeping their repositories on GitHub (Git repository hosting service used for version-controlling IT projects). This free Git GUI is open-source, transparent, and functional. When you consider the Git graphical interface for Windows, GitHub Desktop is often the first option to come to mind.
With this solution, you won’t need to use the command line and enter commands manually. You only need to log in to your account at GitHub and use this GUI to manage your code in a repository.
With GitHub Desktop you can:
- Create new local repositories easily
- Track all changes and their authors visually
- Collaborate with other developers
- Checkout branches with ease
- Code safely with syntax highlighting
GitHub Desktop is supported by a vast community of developers. They work continually to make both Git and this free Git client Windows better for every user.
GitKraken
GitKraken is one of the best-known Git GUI tools for Windows, Linux, and Mac. Specialists favor this software for its reliability and efficiency, and its stylish interface also helped this solution become so popular. It simplifies all the basic tasks, making it possible to perform the necessary actions and fix errors with one click.
It boasts an embedded editor where you can edit the existing code. You can also start new projects without leaving this Git desktop client. Syncing tasks are possible in real-time, and a lot of organization features make it ideal for teamwork.
GitKraken is a free Git client Windows provided you use it for non-commercial purposes. There are also advanced, paid versions – Pro and Enterprise.
- Syntax Highlighting
- Drag and drop functionality
- Tracking all issues
- Support for Gitflow and Git Hooks
- Integration with repository hosting services
GitKraken is one of the most functional and convenient Git UI tools, loved by millions of Git specialists worldwide.
Sourcetree
Sourcetree is another famous software solution that provides Git graphical interface for Windows and Mac. The free Git client software allows you to connect to your repositories in GitHub, Bitbucket, Stash, or Microsoft TFS.
Developed by the Atlassian company, the tool aims to make the life of Git specialists easier. It is simple and user-friendly, with transparent navigation and a bunch of useful features.
You can easily perform all the necessary Git-related tasks, such as cloning repositories (including the remote ones), pushing, pulling, committing, and merging changes. Both experienced users and beginners can work successfully with Sourcetree, tracking all changes, actions, and actors.
features of Sourcetree:
- Support for large Git files
- Detailed branching diagrams
- Reviewing all the changes (both outgoing and incoming)
- Easy maneuvering between branches
- Full support for Git-flow and Hg-flow
The tool is bound to keep your repos cleaner and your development more productive.
Tortoise Git
Tortoise Git is a dedicated solution for working with Git on Windows. It is, in essence, a Windows shell interface. A free Git GUI of an open-source nature allows any team to adjust the functionality or even build a personal Tortoise Git version for specific needs. It can work with any file and does not depend on any IDE.
Git professionals use Tortoise Git to quickly perform all the standard tasks, such as cloning repositories, creating branches, handling changes, viewing logs, etc. A helpful feature is an integration with Windows Explorer – you can perform the necessary jobs in a familiar and convenient environment.
features of Tortoise Git
- Autocompletion of keywords and paths
- High efficiency with large projects in non-linear development
- Easy handling of branches and tags
- Cryptographic authentication of history
- Ability to handle multiple tasks in teamwork
The popularity of Tortoise Git is worldwide. There are 30 different language versions to make the software development jobs faster and more straightforward for developers from various countries.
SmartGit
SmartGit is another functional cross-platform Git client software. It works smoothly on Windows, Mac, and Linux. For many specialists, SmartGit is the easiest Git client.
The SmartGit free Git GUI allows users to perform all the tasks required to work with their repositories. It provides the possibility to view and edit files side-by-side and allows resolving merge conflicts automatically. With Git-Flow support, you can configure branches directly in the tool. There is no need to use any additional software.
- An in-built SSH client
- Commit history in a visual mode
- The Conflict Solver feature for fixing issues when merging files
- The single-view Log window to view commands, index, and working tree at once
- Commit Debugger for verifying any commit if necessary
SmarGit has both free and paid versions with more robust functionality and additional integration features. The easiness of use made this tool favored by many developers. It offers great functionality that is improved continually.
GitForce
GitForce is a popular Git GUI alternative to the command-line. It is a cross-platform solution, running on Linux (including Ubuntu) and Windows. The tool is simple, Smart, and efficient. However, since the overall functionality of Git is versatile, and there are too many options, this Git client software doesn’t cover everything. But it provides a straightforward way to perform the most common commands in a graphical interface. Besides, it is a free Git GUI, available to everyone.
Among the many helpful features of GitForce, you may note multiple repositories support, the possibility to scan local repositories, drag-and-drop functionality, access to history, etc.
features of GitForce:
- No need to install the software – get the single file and execute it
- Create and handle multiple repositories and branches
- A clean and intuitive GUI
- Manage SSH keys easily
- Embedded command-line interface with the ability to pick the commands executed from CLI
Despite some functional limitations, GitForce is a very efficient free Git client Windows. It is suitable for both beginners and experienced Git users. The most valuable benefit is that it can significantly reduce the need to use the command line to a minimum (or even eliminate it).
Git Cola
Git Cola is a free open-source Git desktop client. Initially developed for Linux, it also runs smoothly on Windows, offering numerous efficient features in a customizable interface. There is a variety of tools at your service – and it is possible to rearrange them for your convenience and hide those that aren’t actual.

Git Cola allows its users to carry out all the necessary routines. The tool compares commits, searches for data by message, author, filename, etc., and edits git indexes. It also ensures proper execution of all necessary Git-related commands in a visual mode. An interface with several panes allows you to view different project aspects and track activities.
features of Git Cola
- A dedicated Git-Dag visualizer for branches and commands
- The Commit Message editor
- Keyboard shortcuts to accelerate the task performance
- Remember the layout modifications and restore them on the next launch
- Cool dark mode and stylish custom themes for the Window Manager
Git Cola is one of the most loved Git GUI tools for Windows that is highly useful for Git specialists of all levels.
Aurees
Aurees is a free Git client that is Windows, Mac, and Linux-suitable. It has an account at GitHub, and users should log into that account to use the client. The primary purpose of the tool was editing and publishing Git files with ease. Colored tags simplify the navigation through the Git GUI remote repository.
Like other Git GUI tools for Windows, Aurees allows the user to examine all changes, IDs, tags, and authors who implemented those changes. With the tool, you can easily detect and analyze differences between different data, handle branches, and revert the changes to the previous working copy.
- Sleek and user-friendly interface
- View the commit and merge data in side-by-side Windows to quickly identify and resolve any issues
- Check differences in the advanced built-in editor
This is a powerful free Git GUI alternative to a command-line interface that copes well with the majority of Git jobs. Many developers favor the tool, no matter which OS environment they prefer.
Magit
Magit is not a separate Git desktop client – it is a free plugin with an original text-based interface. It is implemented as a GNU Emacs package to use on Windows, Mac, and Linux. The plugin allows the developers to perform the necessary version control tasks directly in the Emacs window.
This solution is very effective for high-level Git commands. It adjusts the outputs for reading by human operators.
- The possibility to clone repositories locally and pulling changes
- The option to create, merge and rebase branches
- Compiling commits and pushing them to the repository
- Examining the commit history
- Compiling and executing patches
- Adding notes and tags
The functionality lacks some specific options. Still, in general, Magit lets the Git specialists do all their daily jobs from within Emacs.
Fork
Fork is a relatively young, simple, and fast Git client for Windows and Mac. The software is available free of charge, but there is also a paid version with more options.
The distinctive feature of the tool is a tab-based interface that makes the navigation and other organization activities much faster. You can open the websites or applications which you work on directly in Fork. This way, you track your repository-related job results better.
- An advanced view for examining and analyzing differences
- A dedicated repository manager
- A comprehensive file-tree structure of the repository
- Creating and deleting remote repositories
- All major Git commands are supported
Magit is one of the newer solutions, and its functionality is continually enhanced. It reacts to all new challenges fast, and thus delivers all the necessary Git desktop client features.
dbForge Source Control–a Git GUI plugin for SSMS
For those software developers who prefer working with databases using SSMS, Devart has created a specialized solution that enhances SSMS-dbForge Source Control. The add-in is compatible with all popular version controls systems, such as Gitgit and Git-based systems, Mercurial, Perforce, Azure DevOps Server, etc. Implementing this Git GUI alternative developers can accelerate the professional routines significantly and eliminate the human mistake factor.
- Version-controlling database schemas and static table data
- Dedicated and Shared modes
- Support for all main version control operations
- Monitoring all changes, their authors, and causes
- Tracking and resolving conflicts and inconsistencies
- Automating the database development routines using the DevOps approach
In case you are the one who favors having all the necessary options to run your software development routines smoothly in SSMS, Devart has cared about it. dbForge Source Control would suit your purposes by adding the required functionality to your favorite IDE.
Conclusion
The variety of Git GUI tools for Windows allows the developer to find suitable software with no hassle. Even those experienced specialists who know each slightest trick of the command-line interface also often switch to some Git desktop client. The graphic user interface adds to the speed of work and makes the code delivery better-polished and error-free. Choosing the Git client is a matter of personal preferences. The key is, there is always the right tool to pick up.
Download a free trial of dbForge Source Control and embrace version control and collaboration practices in your projects.
Git for Windows 10
Get your commit done. SmartGit is the most popular Git GUI client at slant.co.
100,000 developers around the world trust in SmartGit.
SmartGit supports GitHub, Bitbucket, GitLab and Azure DevOps.
What users say about SmartGit
Ferhat Dogru
Thanks SmartGit, we achieved our goal earlier and flawless as butter. Thank you for that great product again!
Daniel Griscom
I can’t imagine a better way to make sure my changes are consistent and complete.
John Papa
Just purchased SmartGit. Absolutely fantastic github tool. Heads and shoulders better than any other I have used.
Why prefer SmartGit as Git Client?
One for All.
SmartGit assists Git newbies as well as it makes experienced developers more productive.
SmartGit has the same intuitive user interface on Windows, macOS and Linux:
- graphical merge and commit history
- drag and drop commit reordering, merging or rebase
- fast, even for larger repositories
Use your SmartGit license on as many machines and operating systems you like.
Interacting with popular platforms.
SmartGit comes with special integrations for GitHub, Azure DevOps, BitBucket (as well BitBucket Server) and GitLab to create and resolve Pull Requests and Review Комментарии и мнения владельцев.
Of course, you can use SmartGit like any other Git client with your own Git repositories or other hosting providers.
Everything Included.
No need to install and configure additional tools. SmartGit includes all you need:
- intuitive File Compare (no plain wrapper around git diff)
- powerful File Merge (freely editable “Conflict Solver”)
- Git-Flow (high-level branch handling)
- graphical Merge and Commit History
- bundled Git client
- SSH-client
Adopt to Your Needs and Workflows.
A perfect Git client should support your workflows. You can customize SmartGit in various ways:
- Preferences for Merging, Rebasing
- External tools,
- External or built-in Compare or Conflict Solver tools,
- Syntax coloring,
- Keyboard shortcuts,
- Layout of certain views,
- Toolbars,
- Light and dark themes
Register of Companies: HRB 16660 Amtsgericht Traunstein Trade Authorization (Gewerbeerlaubnis n. §14 GewO): Gemeinde Ainring Managing Directors: Thomas Singer, Marc Strapetz
How to install and use Git on Windows
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.
Installing Git on Windows
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’re 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, see: How to create a GitHub repository.
- From the command line, move to the directory you want to contain your Git repository.
- How to change a directory or open a folder.
- Type the following command to configure your Git username, where will be your GitHub username.

git config.-global user.name “”
- After entering the above command, you’ll be returned to the command prompt. Next, enter your e-mail address by typing the following command, where is your e-mail address.
git config.-global user.email “”
- Once the above steps are 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” at https://github.com/Computerhope/example.git address. Copy the address to your clipboard.
- Once copied go back to the command line and type the following command, where is the address you copied. To paste that address into the command line right-click in the command line window and click paste.
- Once the Git repository is created, you’ll have a new directory in your current directory with the name of the Git repository.
- Once the Git remote repository is cloned to your local repository, a new folder in the current directory should appear 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.
- Once in the new directory, type the following command to list the remote repositories.
- If successful, the output is “origin,” a special name that refers to the remote repository.
- 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, are the steps of creating a new file, pushing that file, editing an existing file, and pushing the update.
Creating a new file and pushing to remote repository
- Create a new file in the Git directory by typing the following command from either the Bash or Windows command line. The following command opens and creates 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 ” to open the file in your favorite text editor.
- In the text editor, enter some text into the file and save and exit the file.
- Back at the command line type the following command to get the current status of your branch and untracked files.
- Git displays a window similar to the example shown below, showing that the file we created is new and untracked by Git.
- 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.
- After entering the above command, the file is 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.
- 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 would make sense everyone working on your project.
git commit.m “First example”
You can also type git commit with no additional tags or options. However, when doing this it opens 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.
- Finally, now that changes are moved from your workspace into your local repository it’s ready to be pushed to the remote repository. Type the following command to push all changes to the remote repository.
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.
You’ll be asked for your GitHub username and password if your computer has not logged in to Git from the command line.
Once the file is pushed, it appears in your GitHub remote repository and is available to everyone else who’re working with the same repository.
Modifying a file and pushing to remote repository
- Edit and modify one or more files in your Git.
- Type git status to see the status of all the files not yet committed from the workspace to the local repository.
- 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.
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.
- Once the files are added, type the following command to commit. Change the notes to apply to your commit.
Getting Started. First-Time Git Setup for Windows
git commit.m “Second update”
If you’re working with a lot of other people, we’d recommend you pull (explained below) before committing. If your local repository is not the same as the remote repository (excluding your new changes), the commit fails. For example, if someone has added new files to the remote repository while you’ve been working and you try commit, it fails 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 updates from a repository before committing, it verifies your local repository and the remote repository are the same and prevents 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 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 modifies your local files and it is up to you to manually fix the files with the conflicts.
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 ” hash ” to mark the end.
Another file that is uploaded in-between pulls. 62ee0eeba2e5b94d10574c1a6a68216e9b392e4c
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.
Another file that is uploaded in-between pulls. update1 update2
If you’re working with a big file, it’s a good idea to search the file for “HEAD” because 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.
git commit.m “Fixed the merge conflict”
The example given in this merge conflict is a basic example. When dealing with a file with more than a few lines of text or big sections of code, a merge conflict can get 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
Creating a branch lets you create a duplicate of the master (trunk) and make several updates without affecting the master. For example, when developing a program if a big fix was need that could take weeks or months, a branch could be created for that fix. 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.
- In the Git master directory, type the following command, where “” is the name of the new branch name. For example, we could call the branch “examplebranch”.
- After entering the above command, the prompt (in Git Bash) changes from “master” to the branch name to indicate you’re working in a branch.
- From this point, you can continue to use Git and modify the files how you have in the past.
- 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.
- If you need to push the branch to the remote repository, you can run the following command.
git push.-set-upstream origin
How to merge a branch back into the master
After completing your work, you’ll want to merge it back into the master or another branch by following the steps below.
- Move into the branch you want to merge into. For example, if you wanted to merge back into the master, type the following command.
- Once the merge is performed, add the files.
- Next, commit the changes.
- 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.
To delete the local branch, type the following command.
To delete the remote branch, type the following command.