Basic of Git & GitHub

Mohit Jha
Madgical Techdom — MadTechBits
4 min readNov 30, 2021

--

What is GitHub & it’s used?

GitHub is a code hosting platform for version control and collaboration.
It lets us work together on projects from anywhere.

Install git and create a GitHub account

GitHub account creation

To create your account, you need to go to GitHub’s website and fill out the signup form.

Github official web page

Git installation

For Linux:

  1. First, update your packages.
sudo apt update

2. Install Git

sudo apt-get install gitgit — version

4. Run the following commands with your information to configure GitHub credentials eg:-

git config — global user.name "mkjha"
git config — global user.email “example@mail.com

For Windows:

  1. Go to the official Git website: https://git-scm.com/downloads

2. Click the download link for Windows

Extract and Launch Git Installer:-

3. Go to the download location. Extract and launch the installer.

Launch Git Bash Shell:-

To launch Git Bash open the Windows Start menu, type git bash, and press Enter (or click the application icon).

4. Launch Git Bash to configure GitHub credentials

git config — global user.name "mkjha"
git config — global user.email “example@mail.com

SETUP & INIT

Initialize an existing directory as a Git repository

git init

Retrieve an entire repository from a hosted location via URL

git clone [url]

Create a GitHub Repository:-

A repository is a storage space where your project lives. You can keep code files, text files, images, or any kind of file in a repository. You need a GitHub repository when you have done some changes and are ready to be uploaded.

Enter any repository name and click on “Create Repository”. You can also give a description to your repository (optional).

Now, if you noticed by default a GitHub repository is public which means that anyone can view the contents of this repository, whereas, in a private repository, you can choose who can view the content.

Your repository is successfully created! It will look like the below screenshot:

Once this is done, now you are ready to commit, pull, push and perform all the other operations.

STAGES: —

git status

show modified files in working directory, staged for your next commit

git add [file]

add a file as it looks now to your next commit (stage)

git reset [file]

un-stage a file while retaining the changes in the working directory

git diff

diff of what is changed but not staged

git diff — staged

diff of what is staged but not yet committed

git commit -m “[descriptive message]”

commit your staged content as a new commit snapshot

git pull

Fetch and merge any commits from the tracking remote branch

git push [alias][branch]

Transmit local branch commits to the remote repository branch

BRANCH & MERGE

Isolating work in branches, changing context, and integrating changes

git branch

list your branches. a * will appear next to the currently active branch

git branch [branch-name]

create a new branch at the current commit

git checkout

switch to another branch and check it out into your working directory

git merge [branch]

merge the specified branch’s history into the current one

git log

show all commits in the current branch’s history

TEMPORARY COMMITS

Temporarily store modified, tracked files in order to change branches:-

git stash

Save modified and staged changes

git stash list

list stack-order of stashed file changes

git stash pop

write working from the top of stash stack

git stash drop

discard the changes from the top of the stash stack

Thank you

--

--