Lectures List
capscom technology computer course almora

GIT and Github Version Control System

GIT is a version control system, it is used to collaborate code and used to keep track code.

Nowadays it is very difficult to manage code as your system grow, sometimes we need to share code with our developer partners or with others and need to track changes on code, so GIT is very useful to manage these changes, which makes programmer life very easy.

Nowadays every single programmer must know about GIT and GITHUB.COM to manage code and share code with others.

In this tutorial we learn about all the basic and important  GIT commands to manage code.

Repository

It is a central storage location where different version of files can be stored, mainly it is used by version control system.

Clone

To copying project from remote site.

Staging

In GIT staging area is like as DRAFT save, which a file or multiple files can be stored and can be used in next commit of code changes.

Commit

commit is the process to save code changes from local project to repository.

Download GIT

Download GIT from this link

Where to use GIT commands

GIT commands can write in window shell, or GIT BASH.

Check GIT version

git --version

Configure GIT 

Set global user name and email for GIT

git config --global user.name "Capscom Technology"
git config --global user.email "Capscomtech@gmail.com"

In this tutorial we learn GIT using some world real life examples

We will create the HTML project and will try to track code changes with GIT

First of all create new project folder or navigate to targeted project folder, as you reach there just right click on that folder inside and select git bash here, new small git bash window will open.

Now we are ready to create GIT repository (it is a place where GIT will store our code to track)

Initialize GIT 

git init

with this command GIT will create new repository on that folder, if that folder is hidden, you can unhide or can show hidden files.

Now git is ready to track code, and we can create project ahead by adding new files.

For example we are creating new page saved as index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>CAPSCOM TECHNOLOGY</h1>
</body>
</html>

Now new code added on project, and git know about this file and this code is not available on git repository.

use git status command to check git status

git status

Add file or files in staging area

Add specific file

git add index.html

Add all files

git add .
git add --all
git add -A

Commit 

As you think your code has been done at specific point and want to save in git so that other can use 

git commit -m "Message define what you have done till this special commit"

 

Display list of files

ls

 

Status

Check the status of repo

git status --short

The short flags are

  1. A - Files added to stage
  2. M - Modified files
  3. D - Deleted files
  4. ?? - Untracked files

log

Check the history of commits of a repo.

  • git log
  • git log --oneline

branch

Check the current branch

git branch

 

Create new branch

git branch css-design

 

Check out from a branch

git checkout css-design

 

Create and switch to new branch

git checkout -b fix-errors

 

Merging branches

  1. First checkout to master branch
  2. then merge with branch "css-design"
git merge css-design

 

Delete merged branch

git branch -d css-design

 

Push local repo to github

git remote add origin repo_url

 

Push master branch to the origin repo_url

git push --set-upstream origin master

 

Pull updated repo(Fetch and merge with existing local repo)

git fetch

 

Provide all the changes history 

git fetch origin

 

Check the difference between changes

git diff origin/master

 

Merge origin repo with local repo

git merge origin/master

 

Fetch and merge origin repo

git pull origin

 

Push new changes to origin

git push origin

 

To view all local and remote branches

git branch -a 
git branch -r (for remote braches only)

 

Push only database-implementation branch to origin

git push origin database-implementation

 

git revert Head

git revert HEAD --not-edit

 

git reset

Move back to previous commit and ignore all the changes made after the commit.

git reset 9cd82a6

 

git amend

git commit --amend -m "New message for commit"
Author/Written by: Mr Hemant Singh (Founder)
Terms & Conditions CAPSCOM TECHNOLOGY Pvt. Ltd. का बेहतर रूप से संचालन करने के लिए यहॉ कुछ नियमें और शर्ते लागू है अगर आप कैप्सकॉम टैक्नोलॉजी में पढ़ रहे है तो यह आप पर लागू होता है।