Git Basics

Prior to working at Skillshow as a web developer, I've had minimum exposure to git. I've used it here and there as an upload tool to transfer my files to my server, but I never really took the time to understand the use of git as version control. Since my day-to-day work involves using git, I thought it'd be a good investment to gain a better understanding of it. First things first, time to freshen up on the basics. This post is not meant to be a tutorial, just a quick reference.

$ git config

This one is pretty straightforward; configure settings such as name, email, and etc globally for all projects or per project basis. Add the --global flag to apply global changes.

$ git config [--global] user.name <name>
$ git config [--global] user.email <email>

Create aliases for git commands.

$ git config [--global] alias.<alias> <git command>

Git also has the ability to manually edit these settings in editor mode with the --edit flag.

$ git config [--global] --edit

$ git init

The git init command is the easiest way to transform an existing project into a git repository. This will create a hidden folder, .git, in the directory, which contains all the metadata for the repository.

$ cd <project>
$ git init

The following would create an empty git repository with the directory name given in the parameter.

$ git init <project>

Shared repositories should always be created with the --bare flag. This will initialize an empty git repository that does not contain a working directory, thus making edits and commits impossible for this directory. Repositories created with the --bare flag are marked with a .git extension i.e. project.git.

$ git init --bare <project>

$ git clone

Cloning a repository creates a working directory in the local machine, as well as a connection named "origin" referencing the original remote repository. Remote repositories can be cloned via HTTP or SSH. If the parameter is not supplied, the cloned directory will take on the name of the .

$ git clone <repo> [<directory>]

$ git add

The git add command adds the changes in the current working directory to the staging area. These files or directories are "tracked" and are ready to be committed. Git gives the options of staging changes in a file or changes to all files in a directory.

$ git add <file>
$ git add <directory>

$ git commit

Once a file or files are staged, they can be committed to the project history of the local repository. The git commit command requires that a message be supplied along with each commit. The -a flag can be used to commit all changes in the current working directory.

$ git commit [-a] -m <message>

$ git status

This command provides a quick view of files that are staged, unstaged, and untracked.

$ git status

$ git diff

This command comes in handy at times when you want know what has changed in a file of the working directory. It will display what are deleted and what are added to the parameter.

$ git diff <file>

This article is my 6th oldest. It is 535 words long, and it’s got 0 comments for now.