Introduction to
Git &
Github
Chandra Bose
• GDSC Lead MLRITM • 8x Hackathon winner
• Frontend Developer • Frelancer
• Arbitrum ambassador • Web3 enthusiast
Things you need to know
• Repository - Repo - Folder • Local repo
• Remote repo • Code-Base
• Terminal / Command Line • Version
• Initialize • Configure
🚨 What you should know
#Repository -> project folder
• git init -> inisalisasi repo
#Commit -> riwayat perubahan • git clone -> duplicate repo
#Checkout -> berpindah ke commit lain • git commit -m “ ....” -> pesan commit
#Branch -> cabang dari commit • git add . -> menambahkan semua file
#Merge -> gabungan dua branch • git log -> melihat semua commit yang dilakukan
#Remote -> alamat repo project • git status -> melihat apa ada file yang
#Clone -> duplicate repo dari remote belum ditambahkan
#Push -> mengirim commit ke repo • git checkout -> restore file
#Pull -> getl update dari repo(merge) • git branch -> mengecek ada berapa
#Fetch -> getl update dari repo(no merge) branch
Version Control Sistem
?
?
Git ?
Git is a software which is used to keep track of all
the changes of your project.
Global Information Tracker
Git is a version control system designed to managing multiple versions of a project,
Often involving multiple developers of teams.
GitHub is a web application which serves as
the user interface ( UI ) for Git.
Github
Git hub
Can store your Git repositories created using Git on a remote
server, where users can access from anywhere.
Why Github
Why Github
• Collaboration • Remote Access
• Community and Ecosystem • Public and Private Repositories
• Version Control for No-Code Files • Social Coding Platform
What is Version control system
New Feature
• Track Changes
• Backup and Recovery
• Code Review
New Feature Error
Git V/S Github
Git hub
• CLI Tool (Command Line) • Web based application
• Works Locally • Works on Cloud
• Tracks Changes in a codebase • Provides Interface to view changes
Installation
[Link]
Open your terminal and type git -v
Creating Github account
[Link]
Creating Github account
[Link]
Lets dive into
Some exciting stuff
Git Architecture Remote / Internet
Remote Repo
git push
Local Repo
git commit
Staging Index
git add
Working Area
Local
Git Life cycle of a file
Stages
Untracked Git isn't aware of these files, Happens to newly created files.
Staged Files which are modified will be included in
staged.
Committed Staged files are can be committed to git repo.
Modified Files that are modified since the last commit.
Config your
git environment
$ git config
• Configure options for your git environment.
• We only use this command when we want to add a
user to it.
Setting user info
$ git config --global [Link] “your name”
$ git config --global [Link] “xyz@[Link]”
$ git config --list lists all git configuration
$ git config [Link] displays user name
$ git config [Link] displays user email
Hard-working viewers!
Time for some break
Lets add git to our project /
project
$ git init
• Initialize your repo with git.
• Giving your repo superpowers to track all your
changes.
Branching in Git
feature 1
commit head
Master (default)
Child branch - feature 2
. git
• Its a hidden folder.
• Git uses to store metadata of the repo.
Lets modify few files
Lets modify few files
$ git status
• To check the status of your files.
• Displays current status of working directory.
Current working folder
not being tracked currently
Lets add some files
All files
$ git add .
$ git add [Link]
Untracked Staged
(Files are staged)
To unstage the files
files will be tracked from now
$ git commit -m “msg”
• Save the changes made to files in repo
• Takes a snapshot of all the changes that have
staged since last commit.
all flies at this point of time
$ git commit -m “msg”
• A unique commit ID is generated for every commit.
• Data is stored in your local machine and all the
files are tracked.
UID for present commit
$ git log
• Used to get all the commits that have done till
now.
$ git log
$ git log -n (number)
• Display the total number of commits that want to
be displayed.
$ git diff
• Compares the data of a particular file to another
files of different stages.
$ git rev-parse --short HEAD
• Display the current commit head.
$ git revert commitid
• Undoes previous commit but creating a new commit
that undoes the changes.
• Moves its current commit head to previous one.
$ git branch
• Displays current branch name.
• Also used to do operations on branch by using
additional flags.
$ git reset commitid
• Move the repository back to a previous commit,
discarding any changes made after that commit.
$ git reset is used to unstage the changes
. gitignore
Doesn't track changes
of the files
Branching in Git
feature 1
Master
Child branch - feature 2
$ git checkout -b name
branch name
• To add a new branch.
• Creates and switches to new branch.
$ git checkout name
branch name
• To change to different branch.
• Resets any changes that done in current branch.
$ git branch -d name
branch name
• To remove a branch from the git tree.
Git Architecture Remote / Internet
Remote Repo
git push
Local Repo
git commit
Staging Index
git add
Working Area
Local
$ git remote add name url
remote name remote url
• To add a remote repository from github.
Lets create a remote repo
To create a new repo
Remote repo url
$ git clone repo-url
• To clone the remote repo.
• Create a local copy of a remote repo.
$ git clone repo-url
Remote repo
url
Push & Pull
• git push cmd is used to update the remote repo
with the local changes you made in your local
branch.
• git pull cmd is used to fetch all the changes from
the remote repo or branch and merges them into
local branch.
$ git push remote
Remote repo url
$ git pull remote
$ git fetch origin
defines original repository
• only fetched the data from the repo but doesn't
integrate new data into the working file.
$ git merge
• Integrate the fetched changes into the local branch.
$ git pull origin
defines original repository
• git pull automatically merge the changes into the
local branch.
$ git pull
=
$ git fetch + $ git merge
Clone the repo
•Contributing to open-source projects starts
from cloning the repo.
Create a new branch
•Contributing to open-source projects starts
from cloning the repo.
Stage and commit your
changes
•Commit all the stages with a proper desc
commit message.
Push your branch to
github
Create a PR
Pull request
•Contributing to open-source projects starts
from creating a PR.
Create a PR
Pull request
Thank you
for following till the end
@gdsc-mlritm gdsc@[Link]