Git - Source control system

varatharuban

Varatharuban

Posted on November 2, 2022

Git - Source control system

Source control is similar to a backup with enabled versioning, which enables you to compare changes to earlier versions and undo changes. Furthermore enables teamwork when working on files with multiple developers.

There are two types of source control.

  1. Centralized - SVN is the most popular centralized source control system. It's require connection with central server for all the operations.
  2. De-centralized or Distributed - Git is the famous distributed source control system. Since most of the operations are in local, connection with remote server require only for few operations (eg. pull, push)

Git is a distributed/de-centralized source control system, and it's fast since most of the operations are in local.

There are three local stages and one remote stage.

  • Working directory
  • Staging area (pre-commit holding area)
  • Local repository
  • Remote repository

Image description

Later of Git version 2.28, default branch has changed from master to main.

Github is the most popular git hosting provider.

Git global configurations

git config --global user.name "Ruban B"
git config --global user.email "ruban@gmail.com"
git config --global user.password "GuessMe123"
git config --global init.defaultBranch "main"
git config --global core.editor "notepad++.exe -multilnst -nosession"
git config --global alias.hist "log --all --graph --decorate --oneline"
git config --global diff.tool p4merge
git config --global difftool.p4merge.path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Perforce"
git config --global difftool.prompt false

git config --global --list
git config --global -e  (it will open the .gitconfig file)
Enter fullscreen mode Exit fullscreen mode

Basic Git commands

git version
git clone <git-repo-url>
git status
git add .
git commit -m "Commit message goes here"
git pull origin master
git push origin master

git init
git init -b <branch> <project-folder-name>
git commit -am "it will add and commit together"
git checkout

git ls
git ls-files
git rm <file>
git reset HEAD <file>
git checkout -- <file>

git init
git add .
git status
git commit -m "Commit message goes here"
git status
git remote add origin https://roks@bitbucket.org/roks/client.git
git pull origin master                      
git push -u origin master -f
Enter fullscreen mode Exit fullscreen mode
Commands Description
git version Get the git version
git clone git-repo-url It will download the remote repository to local file system. This operation called as cloning
git status It will show the untracked/modified file details
git add . Add all changes from working directory to staging area
git commit -m "Commit message goes here" Move changes from staging area to local repository
git pull origin master Update local project with remote repository, if any changes made it will available
git push origin master Publish changes to remote repository
git init Initialize a folder with git
git init -b main project-folder-name Initialize with disired branch name
git commit -am "Commit message goes here" It will add to staging area and commit together
git checkout
git ls
git ls-files
git reset HEAD file Un-stage the file
git checkout -- file Revert changes in working area

Create .gitignore file in the root directory, to skip
Specific file
File pattern - *.ext
Folder - myfolder/

origin refers to the name of the remote repository

Thanks.

💖 💪 🙅 🚩
varatharuban
Varatharuban

Posted on November 2, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related