Version Control Using Git

Version Control Using Git

·

3 min read

Hey There! Hope all is well.

I'm Ramya Dhanushkodi, a front-end web developer💻.

I would like to share my learning's from Git from Basics to Advanced: Practical Guide for Developers by Andrii Piatakha.

I recommend this udemy course for both beginners and advanced git users.

What is GIT?

An open source distributed version control system for developers to collaborate and develop small to large scale applications.

What is Version Control System?

A software tool used to keep track of repositories and files within it by keeping tracks of edits.

Why we need GIT?

Imagine yourself working in a team. You and your peers develop different features for an application. Is it easy to combine those? Can you remember what you coded yesterday? How do you know your peers feature implementation?

Git helps you in solving that arise during a multiple phases of project starting from scratch through debugging bugs to releasing the project.

Some advantages of using git are listed below :

  1. Multiple developers can work on same file at same time using git
  2. You can commit and remember your past code
  3. All commits contain the author of it
  4. You can easily find and debug the code
  5. Easy to get back to previous version of code

Repositories in GIT

Repository - A location where all files are stored and maintained by git

Types of Repositories

  1. Local Repo(Kept in your device to manipulate files)
  2. Remote Repo(Kept in website to keep track of changes)

LifeCycle in GIT

git lifecycle.PNG

git init

  • To create a local git repository

git add .

  • To add all file changes

git add file-name.extension

  • To add particular file changes to staging area

git commit -m "Message to show for this commit."

  • Add files to Tracked changes

git commit -a -m "This command will add and commit"

  • Add files to staging area and then commit changes

git push

  • Push changes from local repo to remote repo

git pull

  • Pull changes in remote repo to local repo

git branch "branch-name"

  • Create a branch from current branch

git checkout "branch-name"

  • Move from current branch to mentioned branch name, if branch exists, else throw error

git checkout -b "branch-name"

  • Create a branch and move to the new branch created

Some unpopular GIT commands

git config --global core.editor "vim"

  • To set vim as code editor for git bash

git checkout -

  • To move to previously worked branch in local repo

git status

  • To view the current branch status, displays all modifications and their status

git status -s

  • To view the status with required/limited info of status

git status --help

  • This will open a website with all information related to git status command. Likewise use --help preceded with the command you want to know more. (Eg. git checkout --help)

git stash

  • Record the current state of the working directory and the index and go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.

Hope you had a good time learning/refreshing GIT. Adios! Until next time✌