Git Setup Commands

Jul 12, 2022 | 2 min read

Intro

Why Git?

Git is a popular version control system which was created by Linus Torvalds and is used for:
  • Tracking code change.
  • Track of code editor.
  • Easy collaboration.

Getting Started:

Install Git:

For Debian:

sudo apt install git

For Fedora:

dfn install git

Configure git:

git config --global user.email "test@test.com"

Listing all config:

git config --list

Initializing git:

git init 

Adding New File:

git add .

Seeing Status

git status

Commiting change

git commit -m 'comment'

Cloning repo

git clone http://test.test

Pushing to github

git push origin

or

git push

Git ignore for ignoring files.

Sometimes do don’t want to share some files in a public repo but for testing purpose we need to have those files in the local machine. For this situation we use .gitignore.
First we create a file called .gitignore.
Inside .gitignore file we add the file or folder name to be ignored by git.

touch .gitignore
nano .gitignore

Github SSH

  • Creating Key

    ssh-keygen -t rsa -b 4096 -C "test@test.com"
    
  • Adding key in the Github

    copy the key generated by ssh-keygen in /home/username/.ssh from the file id_rsa.pub and paste that in the github website account settings -> SSH and GPG keys -> New SSH key -> Add SSH Key
  • Testing Connection

    ssh -T git@github.com
    

Push an existing repo

git branch -m master (Here you are creating a branch called master)
git remote add master git@github.com:xxxx (here master is the remote repo identifier)
git push master (if your branch and remote repo name is same)
  • If different identifier name or multiple repo

git push -u origin main (if you have multiple remote repo. Origin is the repo identifier and main is branch name)

Here are some cheats

Cheat 1

Cheat_1

Cheat 2

Cheat_2

Image credit goes to twitter @Sheraj99