Simple Commands for Git

Git commands from when I was learning git

Devin Moreland
All Things DevOps
2 min readJul 11, 2022

--

Recently found this article in my drafts and thought I would share it.

Purpose

Recently, I have been learning about Git on a high level and wanted to create an article as a way to store these simple commands for my future reference and for anyone else who may find them useful.

What is Git

Git is a version control system that allows us to view modifications to code prior to committing them to the main repository where the code is stored. It is very useful for things such as pushing to GitHub or other repositories.

Git

To install Git on our server we use the following command

sudo yum -y install git

Once installed we must create a git repository. While in ~/home/user enter the following. The name of the repo will also be a directory when using ls commands in ~/home/user

git init name_of_repository

Now lets set up a username and email in git so that when we make changes so everyone knows who made the changes. Also we will use vim as out text editor so we will go ahead and add that as well.

git config --global user.name “User Name”

git config --global user.email “email”

git config --global core.editor vim

Lets Change Directory into the newly created repo. We will call this Master from now on. Once in Master we will create our first file. You can do this however you like. We will use 2 different commands to add the same file to demonstrate.

vim file.txt (then enter some text)

echo “this is some text” >> file.txt

Now that this file is created we need to add it to the git staging area by the first command, and then we will commit this file. The first two are the long way, the last command shortens it to one command.

git add file_name

git commit -m “reason for adding file to the repo”

Short cut;

git commit -ma“reason for adding the file to the repo”

Congratulations we now have created a Git Repository along with a file in the repository.

--

--