0% found this document useful (0 votes)
114 views

Github and Git

Git is a version control system that tracks changes to files. GitHub is a hosting platform for Git repositories that provides additional features like issue tracking and code review. The document provides instructions on installing Git and GitHub, using basic Git commands like add, commit, log and revert, and collaborating using features like forking, cloning, and pull requests.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views

Github and Git

Git is a version control system that tracks changes to files. GitHub is a hosting platform for Git repositories that provides additional features like issue tracking and code review. The document provides instructions on installing Git and GitHub, using basic Git commands like add, commit, log and revert, and collaborating using features like forking, cloning, and pull requests.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

GITHUB AND GIT

INTRODUCTION

Git is a Version Control System. Now, what's a VCS?


It is a system that tracks changes made in any set of files, usually
used for coordinating work among programmers.

Git shows what changes were made, when and by whom to a project
INSTALLATION
We will start this module by downloading Git Bash, from the official website
https://git-scm.com/ and follow along for installation.
Launch the Git Bash setup. The very first page contains the important info
regarding the licenses and term & conditions. After reading it click on the
next button.
The next page consists of the components that needs to be installed.
Please confirm that the check box regarding Additional icons has been
marked for it to create a Desktop shortcut.
The next page contain the info about the Default editor (eg. VS Code,
Sublime Text, Vim etc.)that we want to set for Git and in which you are
comfortable.
INSTALLATION
The next page consist of the info about adjusting the name of the initial
branch in new repository. Let it to be the default option i.e “let git decide”. Click
on next.
After that it contains the info about the adjustment of Path environment.Keep
this to be the recommended option(i.e Git from the command line and also
from 3rd-party software). Click on next.
In the next page choose the Use the OpenSSL Library option(default option)
and click on next.
In the next page choose the option (Checkout Windows-style, commit Unix-
style line endings) and click on next.
Again click on next after checking Use MinTTY option. For all further pages stick
with the default options, hence click on next till you reach Installation option.
Get it installed and click on Finish.
INSTALLATION ON
macOS
Go to Git official site and head over to downloads section for macOS
Either use the homebrew method or the package installer →
1)HomeBrew method -
1)Go to homebrew official site and copy the bash command and
paste it in your terminal and enter to install brew for mac
2) Now run the command ‘brew install git’ to install git for your mac

2)Package Installer Method -


1)Download the package installer for mac from the Git official site
2)Run it like a usual application installer on MacOS

Now , you’re all set to push/pull, commit,fork etc with the terminal on mac
BASIC BASH COMMANDS
cd : Allows you to traverse to other directories.
You can use “cd . .” to go to parent directory.

pwd: Displays present working directory

ls : Use this to list files in current directory.


Use “ls -a” to access hidden files or directories. These are
the ones that typically begin with a dot (.)
BASIC BASH COMMANDS
BASIC BASH COMMANDS

mkdir : Allows you to make directory.

touch : Allows you to make a file.

nano : A Command Line Text Editor for editing files in bash.

echo: Display a line of text that is passed in as an argument

cat : Displays the contents of the file


BASIC BASH COMMANDS
BASIC BASH COMMANDS
grep: The grep filter searches a file for a particular pattern of
characters, and displays all lines that contain that pattern.
pipe: It is a form of redirection that is used to send the
output of one command/program/process to another
command/program/process for further processing
> : used for redirecting the output of a program to something
other than stdout
>> : appends to a file or creates the file if it doesn't exist.

The > operator overwrites any existing contents of the file, while
the >> operator appends to the file.
BASIC BASH COMMANDS
INITIALIZING GIT REPO

Inside your Project Folder type: “git init” to initialize git


repository.

It will make a “.git” folder inside your Projects folder.

.git folder is where, all your tracking data goes.

To check the current status of git repo type: “git status”


INITIALIZING GIT REPO

The Staging Area is when git starts tracking and saving


changes that occur in files.

Type: “git add <filename>” (For adding a single file to


staging area)

Type: “git add .” (For adding all the files which you
changed)
COMMITING THE CHANGES

If all things are good you may want to commit changes


to release the new version of your project.

To do this we will use: “git commit” command

Type: “git commit -m <message>”


VIEWING LOGS

There are two ways of viewing history logs:


“git log” : displays all of the commits in the repository’s
history.

“git reflog” : displays the record when the tips of


branches and other references were updated.
REVERTING CHANGES
Let’s suppose you want to revert back to last version of the
file as the current version is buggy or you made some
serious mistake.
So first type: “git diff HEAD” (allows you to compare the
file version in your working directory with the file version
last committed in your remote repository)
To move back to last version ,first check the commit id
using the command: “git reflog”
REVERTING CHANGES

And now to move back to last version type:


“git revert <commit id>”
and the file will revert back to the last version
KEEPING SECRETS PRIVATE
There may be things in some files that you
want to keep private, like API keys.

To prevent git from tracking these files, we


have .gitignore .

.gitignore tells git about the files which it


should not track.

Add the files name (with extension) which you


don’t want to get tracked. And git will not track
those files.
GITHUB -GET FAMILIAR WITH
THE USER INTERFACE
GIT AND GITHUB ARE NOT SAME!
1. GITHUB is not GIT. Both are different
Things.

2. Git is a VCS or Version Control System


which tracks of code changes over a period
of time.

3. While, Github is a hosting platform service


layered over GIT (i.e., uses GIT) for tracking
the code changes but on cloud.
CREATING A GITHUB ACCOUNT

ENTER YOUR EMAIL


GO TO GITHUB.COM AND CREATE YOUR
PASSWORD
FEATURES OF GITHUB...

WHAT IS A REPOSITORY?

A repository contains all of your project's files and


each file's revision history. You can discuss and
manage your project's work within the repository.
CREATING A GITHUB REPOSITORY
1. FInd the plus icon and choose
“New Repository”.

2. Type a short, memorable name for


your repository. For example,
"hello-world".
CREATING A GITHUB REPOSITORY
3. Optionally, add a description
of your repository. For example,
"My first repository on GitHub."

4. Choose a repository visibility.


Your repo can be visible to anyone
(public) or only to the ones you
authorize (Private).

5. Then simply select Initialize this


repository with a README. And
click Create repository.
README
1.The most important part of a git repository is a README.md
file

2. This file summarises about the project and helps other


user to understand about your code.

3 .md refers to Markdown File

4. Some basics of Markdown:


# Text -> Main Heading Level
## Text -> 2nd Heading Level
Google for detail cheatsheet
GITHUB PROFILE README
a. It is a special README file that shows whenever someone
opens your GitHub profile.

b. An awesome place to tell people about yourself, your


interests, projects and just basically leave an impression
onto the visitor.

c. Can include a variety of stuff like Badges, Stats, various


cards like your latest blogs, the songs you listen to, your
email-id and other cool things to show-off!
FORKING AND CLONING
To fork and clone a repository

a. Open a repository.
b. Click on Fork button.
c. Click on Create Fork.

d. Open the forked repo, click on Code and copy the url.
e. Open git bash and type: git clone <your-remote-git-repo-
url>
f. Type: cd <filename>
g. Type: git remote add upstream <your-remote-git-repo-
url>
CREATING A PULL REQUEST
To create a pull request:

a. Open the source repository.

b. Click on Pull Reuqests.

c. Click on New Pull Request.

d. Type a comment and then click Pull Request.

You might also like