Getting Started with Git
Updated by Linode Written by Linode
What is Git?
Git was designed and developed by Linus Torvalds for Linux kernel development. Git provides support for non-linear, distributed development, allowing multiple contributors to work on a project simultaneously. Git is the most popular distributed version control and source code management system. This guide will walk you through the basics of getting started with Git, from installing the software to using basic commands on both local and remote repositories (repo).
After you install Git, configure it for first time use using
git config, a built-in tool that obtains and sets configuration variables. These configuration variables are located in three different places on a GNU/Linux system:
/etc/gitconfig- stores the configuration information for all system users and their respective repositories.
~/.gitconfig- stores user-specific configuration files on the system.
.git/config- this is the configuration file of your current working repository.
For a Windows system, the
.gitconfig file is located in the
$HOME directory of the user’s profile. The full path is
C:\Document and Settings\$USER or
After installing Git make sure your username and email address are set correctly. To verify, use the command:
git config --list
If your name and email are not listed in the output, use the following commands to set them manually, replacing
git config --global user.name examplename git config --global user.email email@example.com
Set your default text editor, replacing
editor-name with your desired editor:
git config --global core.editor editor-name
The output of
git config --list should show echo the information you inputted:
MacBook-Pro:~ user$ git config --list user.name=exampleuser firstname.lastname@example.org core.editor=editor-name
Work with an Existing Local Repository (Repo)
If you have an existing project and you want to start using Git to keep track of its changes, run
git init from the existing project’s directory:
git init creates a new
.git subdirectory in the current directory. This is where Git stores your configurations. The
git add command tells Git to track changes of files:
git add filename
After you have added the file, stage a commit and leave a commit message. Commit message serve as a reminder of the changes that were made to a file:
git commit -m "Initialized a Git repository for this project. tracking changes to a file"
Basic Git Commands
This table lists basic commands, a description, and an example of the command in use:
||Add a file to a repository.||
||Remove a file from a repository.||
||Move or rename a tracked file, directory, or symlink.||
||List all the local and remote branches.||
||Commit all staged objects.||
||Download all changes from the remote repo and merge them in a specified repo file.||
||Publish the changes to the remote repo.||
Branches are used for editing files without disturbing the working portions of a project. The main branch is normally named
master, it’s customary to name the branch after an issue being fixed or a feature being implemented. Because Git keep tracks of file changes, you can jump from branch to branch without overwriting or interfering with other branches in the repo.
The basic options used with the
git branch command are:
|-r||List the remote branches|
|-a||Show both local and remote branches|
|-m||Rename an old branch|
|-d||Delete a branch|
|-r -d||Delete a remote branch|
Working with Remote Repositories
Remote repositories are hosted on a network or another location on the Internet. This section provides some basic information on navigating remote Git repositories.
To copy every file from a remote repository to your local system, use
git clone followed by the remote repo’s URL:
git clone remoteurl
To check the status of the files within the current branch of your repository, use
The output of the
status command will tell you if any tracked files have been modified.
remote to view which remote servers are configured:
remote command will display the short names of your remote repositories. If your repository was cloned, you will see a repository called
origin. The default name origin comes from the cloned repository. To view more information about the remote repositories, use the command:
git remote -v
Below are some basic commands for working with remote repositories:
||Add a new remote repository.|
||Gather all the data from a remote project that you do not have yet.|
||Obtain and merge a remote branch into your current branch.|
||Move your data from your branch to your server.|
||Display information about the remote you specified.|
||Rename a remote.|
||Remove the remote you specified.|
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
Join our Community
This guide is published under a CC BY-ND 4.0 license.