0% found this document useful (0 votes)
75 views12 pages

Git and GitHub

Uploaded by

Jared Murundu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views12 pages

Git and GitHub

Uploaded by

Jared Murundu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Git and GitHub

Introduction
Git is a version control system that manages and keeps track of code changes, while GitHub is a
web-based Git repository hosting service that offers all the distributed revision control and
source code management functionality of Git, as well as adding its own features
Git
Git is a well-known version control program. Since its inception by Linus Torvalds in 2005,
Junio Hamano has been responsible for its upkeep.
Uses of Git
 It is employed to track code modifications.
 monitoring who made the adjustments
 collaboration in coding
How does Git work?
 Utilize repositories to oversee projects.
 To work on a local copy, clone a project.
 Staging and Committing Branch and other tools let you manage and monitor changes.
Merge to enable work on various components and iterations of a project.
 Take a local copy of the project's most recent iteration.
 local updates to the main project via push
Working with Git
 Initialize Git on a folder, making it a Repository.
To initialize Git on a folder and make it a repository, follow these steps.
 Open your terminal or Git Bash and navigate to the root directory of your project.
 Use the "git init" command to initialize the local directory as a Git repository. This
will create a new. git subdirectory in your current working directory and create a new
main branch.
 Add the files in your new local repository using the "git add" command followed by
the file name or "." to add all files in the directory.
 Commit the files that you've staged in your local repository using the "git commit"
command followed by a message describing the changes made.
 Git now creates a hidden folder to keep track of changes in that folder.
 When a file is changed, added or deleted, it is considered modified
 You select the modified files you want to Stage
 The Staged files are Committed, which prompts Git to store a permanent snapshot of the
files
 Git allows you to see the full history of every commit.
 You can revert back to any previous commit.
 Git does not store a separate copy of every file in every commit, but keeps track of
changes made in each commit!

Why Git
 Over 70% of developers use Git!
 Developers can work together from anywhere in the world.
 Developers can see the full history of the project.
 Developers can revert to earlier versions of a project.
Basic Git Commands

In the above example, the code gives out the git version.
The steps are as follows
1. Open the Command Prompt and run it as an administrator
2. Run the code git –version
3. This will give you the git version you are working with on your machine
ii). Configuration of Git
This command git config –global makes both the user’s name and the email to be available in all
the repositories. If you want the to place them in your local environment then you remove global.
Below is a a real practice using the command prompt
iii). Creating a Git folder
The .git folder is a hidden folder that is created when you initialize a Git repository in a project
directory using the "git init" command. This folder contains all the information that is necessary
for your project in version control and all the information about commits, remote repository
address, etc. All of them are present in this folder. The .git folder is essential for Git to track
changes to your codebase and is an integral part of the Git workflow
When creating a folder there are steps you are going to follow Using the
 mkdir- this creates a folder in the local machine
 Cd- changes the working directory to the created folder

iv). Initializing Git


Initializing Git is the process of creating a new Git repository in a project directory or converting
an existing versioned project to a Git repository. The "git init" command is used to initialize a
new Git repository. When you run this command, Git creates a new .git subdirectory in your
current working directory, which contains all the information necessary for your project in
version control. The following basic commands can be followed;
The git init command will initialize git to the working directory

iv). Adding New Files In Git


The files we created are empty and we would wish to add some files in the in them. We can use
HTML to add some files as below
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
</head>
<body>

<h1>Hello world!</h1>
<p>This is the first file in my new Git Repo.</p>

</body>
</html>

Files in Git repository folder can be in one of 2 states,

 Tracked - files that Git knows about and are added to the repository
 Untracked - files that are in your working directory, but not added to the repository

When you first add files to an empty repository, they are all untracked. To get Git to track them,
you need to stage them, or add them to the staging environment.

v). Staging environment


Staged files are files that are ready to be committed to the repository you are working on GitHub.
Once our file jared.html Is ready and we are done with it we add it to the working directory. We
do that as below;
git add jared.html
Once the command runs the jared.html is now staged, when we check the status the follows can
be visible

We can also add more than Two files


To stage several files we use the below
git add –all (this will stage all the files created in the directory)

Git Commit
Once we are done with the exercise, we are prepared to leave the stage and commit to our repo
because we have completed our task. Adding commits allows us to track our development and
modifications as we go along. Each commit is regarded by Git as a "change point" or "save
point." If a bug or adjustment has to be made, you can go back to this point in the project. We
should always provide a message when we commit. You may make it simple for yourself (and
others) to understand what has changed and when by including unambiguous messages in each
commit.
We use
git commit -m “Message”

Checking the history of commits to our repository we use the following


git log
When one needs help on the git commands the commnd to use in that case is
Git help –all as shown below

Git Branches
In Git, branches are a fundamental concept that allows you to work on different parts of your
project concurrently and independently.
In Git, branches are a fundamental concept that allows you to work on different parts of your
project concurrently and independently. Branches are essentially pointers to a specific commit in
the version history of your project.
 Main Branch (usually 'master' or 'main'): This is the primary branch in your Git
repository. It typically represents the stable version of your project.
 Feature Branch: These branches are created to develop new features or work on bug
fixes. They branch off from the main branch, and once the feature is complete, the
changes can be merged back into the main branch.
 Release Branch: Release branches are used to prepare for a new software release. They
are typically used for final testing and bug fixing before a new version of your software is
deployed.
 Hotfix Branch: Hotfix branches are created to fix critical bugs in the main branch,
typically in a production version of your software. They allow you to address issues
without disrupting the ongoing development in feature branches.
 Topic Branch: These branches are created for specific topics or tasks, similar to feature
branches. They are useful when you want to isolate changes related to a particular task or
issue.

Git Branch Merge


Git Workflow

The typical Git workflow involves the following steps:

 Creating a repository.
 Making commits to track changes.
 Creating branches to work on separate features or fixes.
 Merging branches back into the main branch.
 Pushing changes to remote repositories, like GitHub.

Benefits of Version Control

 Version control systems, like Git, provide several advantages, including:


 Tracking changes made to source code and other files.
 Enabling collaboration among team members.
 Managing code versions and facilitating rollbacks if needed.
 Improving productivity and making the development process smoother.

Git for Data Science Projects

 - Git and GitHub can be used in data science projects to track changes to Jupyter notebooks,
datasets, and code.
 - Integration with data science tools like Jupyter, RStudio, or data versioning platforms like DVC
(Data Version Control) allows for better management of data science projects.

Practical Aspect

 Setting up Git involves installing Git on the computer and configuring basic settings.
 Creating a local repository is done using the `git init` command.
 Common Git commands include `git add`, `git commit`, `git status`, and `git log`.
 Branching and merging allow for parallel development and combining changes.
 Collaboration with GitHub involves creating a GitHub account, creating a remote repository, and
pushing local changes to GitHub.
 Cloning and pulling are used to create a local copy of a remote repository and update it with the
latest changes.

GitHub

GitHub, is a platform and cloud-based service for software development and version
control using Git, allowing developers to store and manage their code. It provides the distributed
version control of Git plus access control, bug tracking, software feature requests, task
management, continuous integration, and wikis for every project It is commonly used to
host open-source software development projects. As of January 2023, GitHub reported having
over 100 million developers and more than 372 million repositories, including at least 28 million
public repositories. It is the world's largest source code host as of June 2023.

i). Create a Repository on GitHub

Click on New Repository


Once you fill in the repository name and click create the following appears

git remote add origin URL specifies that you are adding a remote repository,
with the specified URL, as an origin to your local Git repo.

GitHub
 GitHub is a popular platform for hosting Git repositories and facilitating collaboration.
 It provides features like issue tracking, pull requests, and code reviews.
 GitHub allows for remote repositories, where users can push their local changes and collaborate
with others.

It provides hosting for Git repositories and collaboration features like issue tracking, wikis, code reviews,
project management tools etc. Key features include:

 Remote repositories - Repositories are hosted on GitHub and can be cloned to local machines.
 Collaboration - GitHub provides tools for teams to collaborate through pull requests, issues,
wikis etc.
 Access control - User and team permissions can be configured for access to read and/or modify
repositories.
 Project hosting - Websites, documentation, static web pages can be hosted directly from a
GitHub repository.

You might also like