Contents

Git Setup Commands

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:

1
sudo apt install git

For Fedora:

1
dfn install git

Configure git:

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

Listing all config:

1
git config --list

Initializing git:

1
git init 

Adding New File:

1
git add .

Seeing Status

1
git status

Commiting change

1
git commit -m 'comment'

Cloning repo

1
git clone http://test.test

Pushing to github

1
git push origin

or

1
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.

1
2
touch .gitignore
nano .gitignore

Github SSH

  • Creating Key

    1
    
    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

    1
    
    ssh -T git@github.com
    

Push an existing repo

1
2
3
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

1
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

/posts/git/cheat_1.jpeg

Cheat 2

/posts/git/cheat_2.jpeg

Image credit goes to twitter @Sheraj99