Introduction to Git and GitHub

Introduction to Git and GitHub

What is Git?

Git is an Open Source Distributed Version Control System.

What is GitHub?

GitHub is a code hosting service, GitHub is a place where developers store their projects and they work together.

GitHub is a living, ever-changing, searchable record that tells the story of how and why our code is the way it is. The ability to document code effectively using Git (or another version control system) is just as important as being able to ship a feature, write clean code or readable tests.

First you have to download and install Git on your system, after that create a directory/folder in your system. Write the git init command so it will contain the complete history of changes made to that directory.

Note: .git/ folder is always in hidden folder.

Link to download Git

Basic commands of git repositories

Add user name

git config --global user.name “Name” This command is used to configure or set the user name.

git config --global user.name “Name”

Add user email

git config --global user.email “email id” This command is used to set email.

git config --global user.email “email id”

Git init

This command makes the directory a Git repository.

git init

Git status

This command is used to check the status of the repository.

git status

Git add .

This command adds all the files of a repository to the staging area.

git add .

Git commit with message

Git commit -m “message” - This command is used to commit all the changes.

git commit -m "message"

Add remote URL

Need to connect the upstream remote -- the central repository to our local repo.

git remote add upstream <URL>

Git clone

Retrieve an entire repository from a hosted location via URL

git clone <URL>

Git stash Save modified and staged changes. Temporarily store modified, tracked files in order to change branches

git stash

Git stash pop write working from top of stash stack. Temporarily store modified, tracked files in order to change branches

git stash pop

Git log show the commit history for the currently active branch

git log

Git fetch [alias] fetch down all the branches from that Git remote

git fetch [alias]

Git merge [alias]/[branch] merge a remote branch into your current branch to bring it up to date

git merge [alias]/[branch]

Git push [alias] [branch] Transmit local branch commits to the remote repository branch

git push [alias] [branch]

Git pull fetch and merge any commits from the tracking remote branch

git pull