Git Introduction


This entry is part 1 of 5 in the series Git and GitHub

gitlogo

This post is an introduction to git. Git is a version control system. It is used for software development and other version control tasks. As a distributed revision control system that was created by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development. Like the Linux kernel, Git is free software distributed under the terms of the GNU General Public License version 2. A Git directory on your computer is a full-fledged repository with complete history and full version tracking capabilities, independent of network access or a central server.

Software Configuration Management (SCM)

Software configuration management (SCM or S/W CM) is the task of tracking and controlling changes in the software, part of the larger cross-disciplinary field of configuration management. Git is run locally on your local computer and GitHub is on the Internet. Version control is important and learning and using Git saves you time in the long run. Git is not as difficult to learn as you might first think.

Do I Have Git Installed?

First we’ll need to open a terminal or command prompt window. In Windows, we can use cmd. On Mac, press Command and space and type terminal.

Installing Git

Go to the website git-scm.com. Install it for the type of operating system you have. You can get the version number of git. Also, you can exit the git Bash window with exit.

git --version

Free Udemy Course

There is a free Udemy.com course called Git & GitHub Crash Course: Create a Repository From Scratch! by Kalob Taulien.

YouTube Resources

There are lots of instructional videos on git up at YouTube.

Creating a New Project Folder

You first need to decide where you want you new project to be located. I store my data files and projects on the D: drive, not on the C: drive. In Windows File Explorer, create a folder for your project. Suppose you call it MyGitTest and it is located a the root of the D: drive. In Git Bash, to navigate to that folder type cd d:/MyGitTest. Also, just as a way to learn and practice Git, add a text file to that folder. Any file will do. I added mytext.txt. Git allows us to track everything that happens to this folder and everything in it.

Creating a New Git Repository

Open up Git using Git Bash and navigate to your project folder. Some commands are listed below. When you run the command below, a new folder appears in your project folder. git init stands for Git initialization. Be sure you are in the right folder before running this.

git init

After running this command notice that you have an empty Git repository. The screenshot below is what I have on my computer. We need to add something to this repository for tracking to be enabled. We also need to commit it.

To add our text file, just type the command below with the name of your text file.

git add mytext.txt

If you want to add everything, use git add . That’s git add space period. This will add everything that we’ve changed, all at once.

Go ahead and check the status with git status. You will see that changes are to be committed. Let’s commit this text file. We need to come up with a message we want to attach to this commit action. Usually when you first commit a file you use the message initial commit. The -m means message.

git commit -m "initial commit"

Ooops! we get the following message if you have not configured the user.

  • git config –global user.email “myemail@domain.com”
  • git config –global user.name “Your Name”

After entering those 2 commands we can now commit the text file and should see something like the following.

To show your commits, use git log.

Short List of Git Navigation Commands

Here is a short list of a few common and important git folder navigation commands:

command description
cd d:/ go to the D: drive
cd c:/ go to the C: drive
cd d:/mygittest go to the folder mygittest at the root of the D drive
cd test go to the subfolder test (from current folder which is d:/mygittest in this example
cd .. navigate up one level
mkdir test_2 create a new folder called test_2 at the current location

The next thing to do is to begin working with branches. Before we make any major changes to a file, we can create another branch so that we can work safely in that new branch without affecting our master branch. If the changes are not what we wanted, we just need to revert back to the master branch, create another test branch and try again.

Series NavigationGit Part 2 Add Commit Branch Delete Revert >>