Intro to Git & Github

rado_mayank

Mayank Choudhary

Posted on September 21, 2021

Intro to Git & Github

What is Git?
Git is the most popular version control system in the world. Without a version control system, we’ll have to constantly store copies of the entire project in various folders. This is very slow and doesn't scale at all, especially when multiple people have to work on the same project. Well, this is very computationally intensive and no one will love doing so.

Git comes under the Distributed system type, which means every team member has a copy of the project and its history on their machine, so they can save a screenshot on their machine locally. This means if the central server is offline they can synchronize their work directly with the others (which isn't possible in a Centralized system)
So, why Git

  • It is an open-source system
  • Git is super fast and free
  • Operations are easy and scalable

Download for Linux and Unix
It is easiest to install Git on Linux using the preferred package manager of your Linux distribution. If you prefer to build from source, you can find tarballs on kernel.org. The latest version is 2.29.2.

sudo apt-get install git

Download for Windows
Git for Windows Setup

# 32-bit Git for Windows Setup - https://github.com/git-for-windows/git/releases/download/v2.29.2.windows.2/Git-2.29.2.2-32-bit.exe.
# 64-bit Git for Windows Setup - https://github.com/git-for-windows/git/releases/download/v2.29.2.windows.2/Git-2.29.2.2-64-bit.exe.

========================================
How set your username & email
Open your Ubuntu command line(I am going to use it as I work through this post)

git config --global user.name mayank26

For setting up the email

git config --global user.email chaudhary.mayank26@gmail.com

To see user details that you registered as

git config --list

To shows the contents of all directories in the current directory

ls -al

The output will look something like this
image

git init
The “init” command creates a brand new Git repository.

git init

git status
Running git status will show you which files are currently in the staging area.

git status

git add
Running git add moves the file/files in the staging area. This helps you to preview your changes before you commit.
To add a single file

git add

git rm
git rm is used to remove a file from a Git repository.

git rm

is the main function for saving changes to the local repository safely. Commit takes a snapshot of the project and treats it as a version.
git commit
It is the main function for saving changes to the local repository safely. Commit takes a snapshot of the project and treats it as a version.

git commit

git log
This helps you to see the commit history. Each commit has a unique id, the author details, date, time, and the commit message.

git log

git log — oneline
git log — oneline show the shorter version(log in one line). It includes the id and the commit message.

## get commits by a specific author
    git log --author mayank

    ## get commits by message
    ## get commit that contains 'index'
    git log --all --grep index

    ## get commit in the last 2 weeks
    git log --since=2.weeks
Enter fullscreen mode Exit fullscreen mode

What is Github?


image
It is the largest open source community in the world. Open-source software is free for you to use and explore. Amazing developers use GitHub. Contribute code to projects that change how software is built.
To upload your file on GitHub via Git, follow these commands:

## creates a brand new Git repository
git init

## to adds the content of the specified file(s) at the time the add command is run
git add .

## now take the staged snapshot and commits it to the project history.
git commit -m "adding files"

## add your work to the github repo.  
git remote add origin https://github.com/yourusername/your-repo-name.git
git push -u origin master
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
rado_mayank
Mayank Choudhary

Posted on September 21, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Intro to Git & Github
github Intro to Git & Github

September 21, 2021