Git & GitHub

Beginners guide on how to git on terminal

Naman Jain
5 min readOct 9, 2021
Photo by Roman Synkevych on Unsplash

INTRODUCTION:

TO MYSELF-

Hey folks👋 , This is Naman Jain aka namx05. I’m a final year student & I’m learning Bug Bounty/Penetration Testing.

TO BLOG-

This is blog is related to Git & GitHub. Many people (beginner/advance) didn’t know how to use git on terminal. So this is all you need to read.

DISCLAIMER:

This is my first blog to start with, so apologies in advance if I made any mistake.

Also ignore typos, grammar(of course) XD.

Now than, let’s get started :)

Photo by Shelbey Fordyce on Unsplash

What is GitHub?

Free and open source version control system.

What is Version Control?

The management of changes to documents, computer programs, large web sites, and other collection of information.

git code editor?

You can use any text editor to code, but Visual Studio Code is the best B-)

Some Terminologies you need Understand:

DIRECTORY —  Folder.
TERMINAL OR COMMAND LINE — Interface for Text Commands.
CLI — Command Line Interface.
CD — Change Directory.
CODE EDITOR — Word Procrssor for writting code.
REPOSITORY — Project, or the Folder/Place where your Project is kept.
GITHUB — A website to host your repositories online.

Commands at a Glance

GIT TERMINAL COMMANDS:
[NOTE:- ALL COMMANDS ARE IN SMALL LETTERS(CASE)]

CLONE- Brings a repository that is hosted somewhere like Github into a folder on your local machine.
ADD — Track your files and changes in Git.
COMMIT — Save your files in Git.
PUSH — Upload Git commits from remote repo, GitHub.
PULL — Download changes from remote repo to your local machine, the opposite of push.
STATUS — To know the status of the file (is their any modification is or not)
DIFF — Show the difference in changes of file
RESET — Undo the commitment (Kinda same XD)
INIT — Add the folder to repo
REMOTE — To add new remote
LOG — To check the history/logs of file

SSH

GITHUB SSH KEY:


CREATE LOCALLY ON MACHINE:
1. (on terminal) ssh-keygen -t rsa -b 4096 -C “<ur github email ID>”
2. go the directory where the ssh-key has been saved and copy the private key on the file with email.3. GOTO github > settings > SSH and PGP keys > create new ssh key and paste the ssh key that was copied from ssh key file.ADD SSH KEY TO SSH-AGENT:-> eval “$(ssh-agent -s)”
-> ssh-add -K <ssh-key location>

Now the real part begins

FOR EXISTING REPOSITORY:

To PULL the repository:-> git clone <git repo link>

Now to use all the commands, you need to be on the same directory.

FILE ADDING

To add specific file to repo:
-> git add <file name>
To add all the files to repo:
-> git add .
To know the status of file:
-> git status

COMMIT

TO CHECK THE DIFFERENCE(i.e. WHAT CHANGES HAS BEEN MADE :))TO COMMIT THE GIT FILE:-> git commit -m "<your message>" -m "<your message>"-m : message as a description of commit (like what/why changed, etc, etc),
can be a single character or entire message
NOTE:
1. First -m is for first box & Second -m is for second box as show in below box.
2. This file will be saving offline, & not be going live in GitHub.

TO COMMIT ALL THE MODIFIED FILE:
-> git commit -am "description"

PUSH:

TO MAKE THE THE REPO LIVE ON GITHUB:IN-ORDER TO PUSH REPO, YOU NEED TO PROVE THAT U R THE OWNER OF THE REPO. AND TO DO SO YOU'LL REQUIRE AN SSH KEY (You can find the steps somewhere mentioned above)-> git push origin master

FOR NEW REPOSITORY

GO TO THE FOLDER WHICH YOU WANNA ADD TO REPO:
From Terminal-
-> git init
-> git add README.md
-> git commit -m "<your message>" -m "<yout message>"

CREATE THE REPOSITORY ON WEBSITE WITH SAME NAME:
COPY THE SSH LINK
-> git remote add origin <SSH link that u copied above>
TO CHECK
-> git remote -v
-> git push origin master
NOTE:
git push -u origin master
-u is for setting this DEFAULT
i.e. you don't have to write origin master again and again XD

UNDO

TO UNDO THE COMMITS:TO UNDO THE FILE WHICH WERE NOT-
-> git reset <FILENAME>
TO UNDO THE COMMITED FILE--> git reset HEAD~<number of commits you wanna go back>TO UNDO THE PARTICULAR VERSION OF FILE--> git logs (for version history kinda stuff XD) & copy the commit ID,
-> git reset <commit ID kinda stuff that u copied>
TO UNDO WHOLE COMMIT (GET RID OF ALL THE CHANGES FROM A CERTAIN POINT)--> git reset --hard <commit ID>

FORK

Making  a full copy of repository in your profile.- You don't have to find the repository in others profile, as it is fully copied under your profile.- You are free/complete control to make any changes/updates to that repository.

CONCLUSION:

So in this blog you have learnt the following stuffs:-

  • What is Git &GitHub.
  • How to make changes in repository using terminal
  • How to add files in repository.
  • How to add SSH connection.
  • How to UNDO git changes/commits.
  • How to see logs of git commits.
  • Forking repository.
  • etc
  • etc
So that's it for this blog.

I know some of the topics are left, such as Branching, etc. I’ll be covering those topics on Part 2, So stay Tuned for that. Till than practice what you learnt on this blog.

If you like this blog than make sure to give a like, share and follow for more content.

Twitter :- https://twitter.com/namx05

Signing off, Peace ^^

--

--