How to work with Git from command line (Windows)

Introduction

Step 1: Setting the global settings in Git command line

Step 2: Opening the file with appropriate exit

Conclusion


Introduction

This post will describe how to work with Git from command line in Windows. It’s very important to know the commands behind the UI in Visual Studio, so this post will explain the basics of what you need to know to work with Git from command line. The Git command line is the only place you can run all Git commands. If you know how to run the command line version, you can probably also figure out how to run the GUI version, though the opposite is not necessarily true. To run the command line version, you need to have at least a basic understanding of how to open Terminal in Mac or Command Prompt or Powershell in Windows.

Step 1: Setting the global settings in Git command line

After installation of Git, the first thing is to set your user name and email address. This is very significant as every Git commit is using this information and it is unchangeable baked into the commits you start creating.

The first step is to set the global settings, but first list display what it’s value.

1. First we will display list to show the value. Type command <git config –global -l> and if there are no settings it will show that there is no such a file. If data exists, then it will display as following:

1-1 Setting the global settings in Git command line-git-config-global-l

2. If you open the user folder, you can see that file <.getconfig>. You will find that this data has been set also in Visual Studio. To check that, open Visual Studio and navigate to global settings. This file can also be edited using VIM.

1-2 Setting the global settings in Git command line git-config-global-e

3. When Unix editor window opens and if you want to quit that window, then type <q +enter>. You can press <i> to start entering text and save by pressing esc and <wq> and enter, this will commit with the message you typed. If you just want to come out from your current state without committing, you can type <q>.

1-3 Setting the global settings in Git command linegit-config-global-e-edit

 

Step 2: Opening the file with appropriate exit

1. If you open the file without appropriate exit, it will create a swap file and you can’t open it again smoothly, you just need to delete that swap file or close the file as described in Step 1.

2-Opening the file with appropriate exit -gitconfig-swp2

You can use also some other commands to achieve different actions; here are some of the most useful ones::

Navigate to the directory you want to use and type:

This will copy all files to your local files, try to add new file and then add it using 

Try to see the status using

Commit the changes

Change the branch

Push changes

Conclusion

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git allows and encourages you to have multiple local branches that can be entirely independent of each other. The creation, merging, and deletion of those lines of development takes seconds. There are ways to accomplish some of this with other systems, but the work involved is much more difficult and error-prone. Git makes this process incredibly easy and it changes the way most developers work when they learn it.

Share This: