Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.


It is important to know the commands for git

Setup and Config

Find the version

git version

Prints the Git suite version that the git program came from.

Open the global configuration file

git config --global --edit

The first time you use Git, you need need to define the user settings.

Define username

git config --global <name>

The first time you use Git, you need need to define the user. The username is the same from Github, BitBucket ot GitLab

Define email

git config --global <email>

The first time you use Git, you need need to define the user. The email is the same from Github, BitBucket or GitLab

Getting and Creating Projects

Find the repo you want from Github/BitBucket/GitLab or make your own

Clone a repository into a new directory

git clone <repo>

Write the command in the terminal. Replace <repo> with the URL of the repo

Basic Snapshotting

Upload the changes you have made

List which files are staged, unstaged, and untracked.

git status

Displays paths that have differences between the index file and the current HEAD commit, paths that have differences between the working tree and the index file, and paths in the working tree that are not tracked by Git

Stage all changes

git add . 

This command updates the index using the current content found in the working tree, to prepare the content staged for the next commit.
The "index" holds a snapshot of the content of the working tree, and it is this snapshot that is taken as the contents of the next commit. Thus after making any changes to the working tree, and before running the commit command, you must use the add command to add any new or modified files to the index.

Commit the staged snapshot

git commit -m "<message>"

Create a new commit containing the current contents of the index and the given log message describing the changes.

Sharing and Updating Projects

You can share your repo on Github/BitBucket/GitLab, so you can work together as a team.

See the changes

git fetch

is the command that tells your local git to retrieve the latest meta-data info from the original (yet doesn’t do any file transferring. It’s more like just checking to see if there are any changes available)

Download the changes

git pull

Incorporates changes from a remote repository into the current branch. It brings (copy) those changes from the remote repository

Upload the changes

git push

Updates remote refs using local refs, while sending objects necessary to complete the given refs.

Rolling back to Last commit

git checkout HEAD <FileName>

It rolls back all changes that have been made to the file, since last commit. It will change your working dircetory to look exactly as it did when you last made a commit

git diff

To see if the rollback was successful. If the command doesn’t output anything, this means your working directory matches your last commit.

Make a new version

git branch

Shows a list of all the branches you have

git checkout <branch>

The git checkout command is used to switch branches and check content out into your working directory.

git merge

The git merge tool is used to merge one or more branches into the branch you have checked out. It will then advance the current branch to the result of the merge.

IF you want to learn more about Git. Go to Git's own website