Git Commands Tutorial - Part 1
In this post, we introduce the basic git commands you need to know to successfully work with git. Read on to learn how to use git from the terminal!
Join the DZone community and get the full member experience.Join For Free
There are many different ways to use Git. The most common are the original command line tools and GUI ( Graphical User Interfaces). Here, we will cover the most important commands you should know about when you are working with Git.
The 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. Also, while your choice of graphical client is a matter of personal taste, all users will have the command-line tools installed and available. You can read more on git's official online book.
Before we start, be sure to know how to use the Terminal in Mac or Command Prompt or Powershell in Windows and have git installed on your system.
First, you might ask yourself what is Git actually and what can you do with it? Git is a fast, scalable, distributed revision control system with a rich command set that provides both high-level operations and full access to internals.
At Kolosek (where I work), we use Git for every application we create, including Ruby on Rails projects, to make it easier to work as a team and achieve our goal.
You can learn a lot about individual Git commands by the running
$git help command in the terminal. This should appear:
Everything can be added to your git repositories, even your Controller tests!
We will cover the most commonly used command lines, starting from Git options. This will explain everything you need to know about Git on your local machine:
usage: git [--version] [--help] [-C <path>] [-c name=value] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path] [-p | --paginate | --no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] <command> [<args>]
$git --version: Find out your current Git suite version using this command.
$git --help: Every good programmer should know about this option, it will show you the most used Git Commands, and it can also print all available commands with
$git -C <path>: Instead of running Git from the current working directory, you can run it from the given
-C <path>command affects other options that expect path names like
--work-treebecause their path names would be made relative to the working directory caused by the
$git -c <name>=<value>: You can very easily override values from your configuration files. The
<name>has to be in the same format as listed by git config, while the
<value>is your new parameter value.
$git --exec-path[=<path>]: This command helps you find the path where your core Git programs are installed. Another way to do this is by setting the
$git --git-dir=<path>: Always use this option, whenever you need to set a path to the repository or set the
And, that's it! For now, at least.
This was only the first part of the tutorial! In the next one, we will cover all the other Git commands, be sure to stay tuned.
Published at DZone with permission of Kristina Pomorisac, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.