Getting Started With Git

1 minute read

Getting Started with the GIT Version Control System

What is Git?

Installation

Linux

  1. Debian
    sudo apt-get install git -y
    
  2. Redhat
    sudo rpm install git -y
    
  3. Using the yum package manager
    sudo yum install git -y
    

    MacOSX

brew install git

Basic commands

Basic Configuration

git config user.email <youremail@example.com>
git config user.name "Your Name"
Or Edit the ~/.gitconfig file on unix-based platforms
[user]
name = Your Name
email = <youremail@example.com>
[core]
editor = vim
pager = less -S

[color]
ui = true
diff = auto
status = auto
grep = auto
interactive = auto

[merge]
tool = vimdiff
[alias]
ci = commit
lg = log --all --abbrev-commit --decorate --graph --oneline
st = status
co = checkout
mt = mergetool

[credential]
helper = cache

[help]
autocorrect = 10

Creating a new repository

mkdir new_repo
cd new_repo
git init .
git remote add origin <git@your-remote-url.com:username/repo_name.git>

Commits

git add . # Add all files in source tree
git commit # Add files to git
git commit -m "Commit Message" # without opening your editor

Commit History

git log --all --abbrev-commit --decorate --graph --oneline

Branching

git checkout -b new_branch # Create and switch to new branch
git checkout master  # Go to branch named master
git checkout commithash  # Checkout the state of the repository as at the commit
#hash

Categories: ,

Updated: