Tech

What is GIT? GIT–Version Control System

What is GIT?

Git is a popular Version Control System.

The aim of Git is to manage software development projects, and its files, as they are changing over time. Git stores this information in a data structure called a repository!

A git repository is a central place where developers store, share, test and collaborate on web projects.

A repository is kind of like an enhanced Unix directory, or folder, but with the additional ability to track changes to every file and subdirectory.

The way to create a new repository with Git is with the “init” command (short for “initialize”_, which creates a special hidden directory called “.git”, where Git stores the information it needs to track our projects changes.

*Note: It’s the presence of a properly configured “.git” directory that distinguishes a Git repository from a regular directory.

Also, all Git commands consist of the command-line program “git” followed by the name of the command, so the full command to initialize a repository is “git init”.

The Main Git status sequence for a changing file:

  • git init‘ –> Untracked/Unstaged –> ‘git add‘ –> Staged –> ‘git commit‘ –> Local Repository –> ‘git push‘ –> Remote Repository
  • Note: Git won’t let us initialize a repository that’s empty, so add at least a first “dummy” file before running ‘git init‘.

A file that is “untracked”, means Git doesn’t yet know about it. We can add it using the “git add” command, moving it to a ‘staging’ area!

Ex’s are: git add or git add -A (Here the ‘-A’ flag option tells Git to add all untracked files.

Note: Throughout this sequence, running “git status” will let us know the status of the file, meaning where it’s at in the sequence. “git log”–shows a record of our commits.

git help‘–brings up Git help documentation.

Note: As we can with the CLI, we can add options, aka flags (arguments) to Git commands, such as: ex: ‘git commit -m‘ (-m adds a message indicating the purpose of the commit).

git diff–similar to the Unix ‘diff‘ utility for the CLI, that lets us compare two files. Git has this similar function ‘git diff‘, which by default just shows the difference between the last commit and un-staged changes in the current project.