8 - 11 - Introduction To Github

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Introduction to Github

Collaboration and version control are important for software development. GitHub has become an
important platform for developers, enabling seamless teamwork and efficient project management.

What Is Version Control?

 A system called version control, sometimes referred to as source control or revision control,
keeps track of changes made to a file or group of files over time so that you may retrieve
particular versions at a later time.
 Although it can be applied to any circumstance where several versions of something are
made and may need to be monitored and recalled, it is most frequently employed in
software development.

What is GitHub?

 GitHub is a web-based platform that uses Git, a version control system, to help developers
manage and track changes in their code.
 It allows multiple people to collaborate on a project, track revisions, and contribute to code
from anywhere in the world.
 GitHub offers both free and paid plans, catering to individuals and large organizations.

Key Features of GitHub

1. Version Control: GitHub’s core functionality is based on Git, which allows you to keep track of
changes in your code over time. This means you can always revert to a previous version if something
goes wrong, compare different versions, and understand the history of your project.

2. Repositories: A repository (or repo) is a central place where all the files for a project are stored.
Each repository can hold multiple files and folders, and it tracks the history of every change made.
Repositories can be public (accessible to everyone) or private (restricted access).

3. Branches: Branches are a crucial feature in GitHub that enable parallel development. You can
create a branch to work on a new feature or fix a bug without affecting the main codebase. Once
your changes are ready, you can merge the branch back into the main branch.

4. Pull Requests: Pull requests are a way to propose changes to a repository. When you submit a pull
request, you’re asking the project maintainers to review and merge your changes into the main
codebase. This feature promotes collaboration and ensures code quality through peer review.

5. Issues and Project Management: GitHub provides tools to track bugs, enhancements, and other
tasks through the Issues feature. You can create issues, assign them to team members, and track
their progress. GitHub also offers project boards for more advanced project management.

6. Actions and Automation: GitHub Actions allow you to automate workflows, such as running tests
or deploying code, directly from your repository. This feature enhances productivity and ensures
consistency across development processes.
Getting Started with GitHub

1. Creating a GitHub Account

Step 1: Go to github.com and enter the required user credentials asked on the site and then click on
the SignUp for GitHub button.

2. Creating a Repository

To create a new repository on GitHub, follow these steps:

Step 1: Then Click on Finish Sign Up. The account has been created. The user is automatically
redirected to your Dashboard.
3. To create a new repository on GitHub, follow these steps:

a) Go to GitHub and log in.


b) Click the “+” icon in the upper right corner and select “New repository.”
c) Enter a repository name and description.
d) Choose whether the repository will be public or private.
e) Click “Create repository.”

Basic Git Commands with Examples


cd <file path> command

First, you have to create a file where your code will be stored on
your pc. For that, you have to create a file on your desktop. After
that open Git Bash and type cd <File directory> to go to file and
branch.

git clone command

If you want to open-source contribution. First, you have to copy


an existing repository (the repository, where you want to
contribute) on your local repository (Your repository). For that,
you have to click the fork button on the repo of the existing
repository on GitHub.
 What is forking: Forking any repository means make a
copy of a real repository in your GitHub account and make
changes in your copy. Thus, a real repository won’t get
affected by your code changes. (After that you have to
make a pull request to the real repository for merging
your code change, we will come to that part later)
 How to do fork: Just go to the real repo and tap on the
fork button

 Copy URL: Then a copy of real repository will be created


in your local repository. After that, you have to copy the
URL from your local repo. For doing that click to code and
copy the URL.

 After that, you have to create a file on your desktop. Then


open Git Bash and go to the file using cd command and
click enter and type git clone <copied url> to copy the
code in your desktop file. With that, you are able to get
the code on your desktop.
git status command

After making code changes you have to add the files for that you
have to check which files are not added. For that use git status.
The command git status can show you the status of your current
file whether it is added or committed or pushed.

git add <File name> command

When you get to know which files are not added by typing git
status(red-colored files are not added). Then type git add <file
name> to add files.

git commit -m <message> or git commit -am<message>


command

After that, you have to commit those added files (type git status
to check status, and green colored files are not yet committed).
Type git commit -m <message> (message is nothing but a text
that tells about what is changed in files) (there are many types of
commit command you can check out git documentation in git
official website).

git push command

At last, you have to push your code changes in your local repo by
typing git push and then make a pull request.

 How to make a pull request: After pushing your code


to your local repository you have to make a pull request
to merge your code to the real repository. To do that just
go to your local repo and click on the pull request.
Important Git Commands

1. git init

Initialize a new Git repository.

git init [directory]

2. git clone

Clone a repository into a new directory.

git clone <repository-url> [<directory>]

3. git add

Add file contents to the index (staging area) for commit.

git add <file1> [<file2> ...]

4. git commit

Record changes to the repository.

git commit -m "Commit message"

5. git status

Show the working tree status.

git status

6. git push

Update remote refs along with associated objects.


git push <remote> <branch>

7. git pull

Fetch from and integrate with another repository or a local branch.

git pull [<remote> [<branch>]]

8. git branch

List, create, or delete branches.

git branch [-r | -a] [--list] [<branchname>]

9. git checkout

Switch branches or restore working tree files.

git checkout [<branchname>]

10. git merge

Join two or more development histories together.

git merge <branchname>

11. git log

Show commit logs.

git log [<options>] [<revision range>] [[--] <path>...]

12. git remote

Manage set of tracked repositories.

git remote [-v | --verbose]

13. git fetch

Download objects and refs from another repository.

git fetch [<options>] [<repository> [<refspec>...]]

14. git reset

Reset current HEAD to the specified state.

git reset [<commit>]

15. git rebase


Reapply commits on top of another base tip.

git rebase [<options>] [--onto <newbase>] [<upstream>] [<branch>]


Difference Between Git And GitHub

Feature Git GitHub


Type Version control system Web-based hosting service for Git repositories
Tracks changes in source code Facilitates collaboration on Git repositories and
Purpose
during development provides a platform for managing repositories
Tom Preston-Werner, Chris Wanstrath, PJ Hyett,
Creator Linus Torvalds
Scott Chacon
Launch Date 2005 2008
Command-line
Yes No
Interface
Graphical User
No Yes (web interface)
Interface
Hosting Git repositories, collaboration, and
Primary Use Version control for code
project management
Repositories Local repositories Remote repositories hosted on GitHub
Authentication None (local use) Uses GitHub account credentials
Collaboration Tools Branching, merging Pull requests, issues, projects, wikis, discussions
Continuous
Supported via external tools Built-in CI/CD with GitHub Actions
Integration
Code Review No Yes (via pull requests)
Local machine or self-hosted
Hosting GitHub servers
servers
Private
Not applicable (local) Available (free and paid plans)
Repositories
No (GitHub itself is not open source, but it hosts
Open Source Yes
open source projects)
GitHub Pages, GitHub Actions, GitHub Packages,
Additional Features Direct use of Git commands
code insights

Companies and Projects Using GIT

The reputed and dream job companies of all the geeks like Microsoft, Google, Facebook, Twitter,
LinkedIn, and Netflix make use of GIT.

Open source projects like Ruby On Rails, jQuery, Perl, Debian, the Linux Kernel, and many more make
use of git.

You might also like