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

Github

The document outlines a course on Git and GitHub, divided into two modules focusing on version control and practical usage. It covers the importance of version control, differences between Git and GitHub, and provides step-by-step instructions for installation, configuration, and common commands. Additionally, it introduces GitHub Copilot, an AI-powered coding assistant, and offers best practices for its use.

Uploaded by

yijoso6936
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Github

The document outlines a course on Git and GitHub, divided into two modules focusing on version control and practical usage. It covers the importance of version control, differences between Git and GitHub, and provides step-by-step instructions for installation, configuration, and common commands. Additionally, it introduces GitHub Copilot, an AI-powered coding assistant, and offers best practices for its use.

Uploaded by

yijoso6936
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

GitHub

For Youth
March 19th 2025
This course is divided into
2 Modules

Course Module 1: Introduction to Git & GitHub


Structure Module 2: Working with Git & GitHub
Introduction to
Git & GitHub
Importance of Version Control
Definition and Purpose:
• Version control tracks and manages code changes efficiently.
• Helps developers revert to previous states when needed.

Benefits for Developers:


• Enables collaboration by syncing code among multiple contributors.
• Prevents code conflicts by managing different versions properly.

Types of Version Control:


• Centralized version control stores all versions in a single location.
• Distributed version control allows multiple copies for local changes.
Difference Between Git & GitHub

• A distributed version control system for tracking code changes.


Git Overview: • Allows developers to work offline and sync changes later.

• A cloud-based platform for hosting Git repositories.


GitHub Overview: • Provides collaboration tools like issue tracking and pull requests.

• Git manages code locally, while GitHub is an online repository.


Key Differences: • GitHub enhances Git with team collaboration and project
management tools.
How Version Control Helps Developers

Collaboration and Code History and Efficient Code


Coordination: Rollback: Management:
• Enables multiple • Tracks all changes • Streamlines software
developers to work and allows reverting development with
on the same project. to previous versions. structured
• Prevents code • Helps identify and fix versioning.
conflicts by errors introduced in • Reduces duplication
managing parallel past commits. and ensures better
changes efficiently. code integration.
Real-World Examples of Version Control
Software • Used in open-source projects for global collaboration.
Development • Enables multiple developers to contribute to large
Projects: codebases.

• Tracks changes in proprietary software across teams.


Corporate and
• Ensures compliance with industry standards and
Enterprise Use: regulations.

Academic and • Manages document revisions and coding assignments.


Research • Helps researchers track and share experiment data
Applications: efficiently.
Installing Git (Windows, Mac, Linux)
Windows Mac Linux
Installation: Installation: Installation:

Install Git using Use package


Download Git
Homebrew or managers like
from the official
Xcode Command APT (Ubuntu) or
website.
Line Tools. YUM (CentOS).

Confirm
Run the installer Verify installation
installation and
and configure with terminal
set up system-
default settings. commands.
wide access.
Verifying Git Installation (git --version)

Checking Git Installation:


Troubleshooting Installation Issues:
Open a terminal or
command prompt. Updating Git:
Ensure Git is added to
Run git --version to the system path.
confirm installation. Use git update-git-for-
Reinstall Git if the windows on Windows.
command is not
recognized. Run brew upgrade git on
Mac and sudo apt
update && sudo apt
upgrade git on Linux.
Configuring Git with User Details (git config)
Setting Up User Identity:
• Configure global username with git config --global user.name "Your Name".
• Set email with git config --global user.email "[email protected]".

Viewing Configurations:
• Use git config --list to check current settings.
• Modify specific settings using git config --global --edit.

Local vs. Global Configurations:


• Global settings apply to all repositories.
• Local configurations override global settings for specific projects.
Setting Up Global Username and Email
Why User • Git uses them to track changes in repositories.
Details Are • Ensures correct author information in commit
Important: history.

Setting Global • Use git config --global user.name "Your Name".


Username: • This applies to all Git projects on your system.

• Use git config --global user.email


Setting Global "[email protected]".
Email:
• Matches your commits with your GitHub account.
Setting Up Git on an IDE (VS Code, IntelliJ)

Installing Git in • Verify Git is installed before configuring the IDE.


the IDE: • Install Git-related extensions or plugins if needed.

Connecting • Use built-in Git integration for cloning repositories.


GitHub to the • Authenticate with SSH or HTTPS for repository
IDE: access.

• Perform commits, pushes, and pulls using GUI


Using Git tools.
Commands in
the IDE: • Access terminal for running Git commands
manually.
Working with
Git & GitHub
Initializing a Repository (git init)
What Is a Git Repository?
• A storage space where Git tracks file changes.
• Allows developers to manage project versions efficiently.

Using git init:


• Creates a new Git repository in a folder.
• Run git init inside the project directory.

Checking Initialization:
• A hidden .git folder appears after initialization.
• Use ls -a to view hidden files in the repository.
Cloning a Repository (git clone)

• Creates a local copy of an existing repository.


What Is Cloning? • Allows developers to work on projects stored on GitHub.

• Run git clone <repository-url> to copy the project.


Using git clone: • Downloads the entire repository, including history.

• Use HTTPS for simple access requiring credentials.


Cloning Methods: • Use SSH for secure, password-free authentication.
Checking Repository Status (git status)
Purpose of git Using git Understanding
status: status: the Output:

Shows the Run git status Red files are


current state of inside a Git untracked
the repository. repository. changes.

Indicates Green files are


Displays file
untracked, staged and
changes before
modified, and ready for
committing.
staged files. commit.
Viewing Configured Git Settings (git config --list)
What Is Git • Stores user and system settings for Git.
Configuration? • Includes username, email, and default editor.

Checking Git • Run git config --list to view current settings.


Configuration: • Displays all configured values in a list format.

Modifying Git • Use git config --global for system-wide changes.


Configuration: • Use git config --local for project-specific settings.
Adding Files to the Staging Area (git add)
What Is Staging?
• Prepares selected files for the next commit.
• Allows tracking specific changes before committing.

Using git add:


• Run git add <filename> to stage a file.
• Use git add . to stage all modified files.

Checking Staged Files:


• Run git status to see staged changes.
• Staged files appear in green before committing.
Checking Staged Files Before Committing
(git diff --staged)
• Shows changes made to files before committing.
What Is git diff? • Helps review modifications before finalizing.

Using git diff -- • Run git diff --staged to see staged changes.
staged: • Compares staged files with the last commit.

Benefits of Checking • Ensures only necessary changes are committed.


Differences: • Prevents accidental commits of unwanted modifications.
Committing Changes with a Message
(git commit -m "message")
Best Practices for
What Is a Commit? Using git commit:
Commit Messages:
• Saves staged • Run git commit -m • Keep messages
changes "Your message" to clear and concise.
permanently in the save changes. • Use meaningful
repository. • The message descriptions for
• Creates a snapshot should describe better project
of the project at what was modified. tracking.
that point.
Viewing Commit History (git log)
• Displays a list of all past commits
in the repository.
What Is git log? • Helps track project changes over
time.
• Run git log to view commit history
with details.
Using git log: • Shows commit ID, author, date, and
message.
• Use git log --oneline for a
Filtering Commit condensed view.
History: • Use git log --author="Name" to filter
commits by a user.
Viewing the Last Commit Details (git show)
• Displays detailed information about a specific
What Is git commit.
show? • Shows commit message, author, timestamp, and file
changes.

• Run git show <commit-id> to see details of a commit.


Using git show: • Without an ID, git show displays the most recent
commit.

• To verify exact changes made in a commit.


When to Use git
show: • To check commit history before merging or reverting
changes.
Removing Files from Staging (git reset)
• Removes files from the staging area without deleting
Why Use git reset? them.
• Helps fix mistakes before committing.

• Run git reset <filename> to unstage a specific file.


Using git reset: • Use git reset to remove all staged files.

• git reset keeps the file but removes it from staging.


Difference Between
• git rm removes the file from both Git tracking and the
git reset and git rm: working directory.
Connecting a Local Repo to GitHub (git remote
add origin)
What Is a Remote Repository?
• A version of the repository stored on GitHub.
• Allows collaboration by syncing local changes online.
Using git remote add origin:
• Run git remote add origin <repo-URL> to link a local repo.
• Associates the local project with the GitHub repository.
Verifying the Remote Connection:
• Run git remote -v to check the linked repository.
• Ensures the local repo is correctly connected to GitHub.
Pushing to GitHub (git push origin main)
What Is Pushing • Uploads local commits to a remote repository.
in Git? • Makes changes available for others to access.

• Run git push origin main to push changes to the


main branch.
Using git push:
• Ensures local commits are synchronized with
GitHub.

• First push requires git push -u origin main to track


Initial vs. the branch.
Subsequent
Pushes: • Later pushes only need git push to update the
remote.
Pulling Updates (git pull origin main)

What Is Pulling in When to Use git


Using git pull:
Git? pull:
• Downloads • Run git pull origin • Before making
changes from a main to fetch and changes to avoid
remote repository. merge updates. conflicts.
• Updates the local • Ensures the local • When
branch with the repository stays collaborating with
latest remote up to date. others to sync
changes. new commits.
Understanding Remote Repositories
What Is a Remote Repository?

• A Git repository stored on a remote server like GitHub.


• Enables multiple contributors to work on the same project.

Key Features of Remote Repositories:

• Stores project history securely online.


• Allows access from different locations and devices.

Local vs. Remote Repositories:

• Local repositories exist only on a developer’s computer.


• Remote repositories store changes in the cloud for collaboration.
Checking Remote Branches (git branch -r)
What Are Remote Branches?

• Branches stored on a remote repository like GitHub.


• Allows teams to work on different features separately.

Using git branch -r:

• Run git branch -r to list all remote branches.


• Displays branches that exist on the remote server.

When to Check Remote Branches:

• Before switching to a remote branch for collaboration.


• To verify if a newly pushed branch is available remotely.
Creating Branches (git branch new-feature)

What Is a Branch in • A separate line of development within a project.


• Allows developers to work on new features without affecting the
Git? main code.

Using git branch to • Run git branch <new-feature> to create a new branch.
Create a New Branch: • The new branch stores changes separately from the main branch.

• Keeps different tasks organized without disrupting the main branch.


Why Use Branches? • Enables multiple team members to work on different features
simultaneously.
Switching Branches (git checkout new-feature)
Why Switch Using git Checking the
Branches? checkout: Active Branch:
• To move between • Run git checkout • Run git branch --
different versions <branch-name> show-current to
of the project. to switch verify the current
• Allows working on branches. branch.
multiple features • Ensures changes • Helps prevent
without mixing are made in the accidental
changes. correct branch. changes in the
wrong branch.
Merging Branches (git merge new-feature)

What Is Merging in • Combines changes from one branch into another.


Git? • Integrates new features or fixes into the main branch.

• Run git merge <branch-name> to merge changes.


Using git merge: • Ensures that the branch’s work is added to the target
branch.

• After completing development or fixing a bug.


When to Merge a
• Before deleting a feature branch after merging it
Branch: successfully.
Listing All Branches (git branch)
• Helps check available branches in a repository.
Why List
Branches? • Useful when working with multiple
development versions.

• Run git branch to list all local branches.


Using git
branch: • Shows the currently active branch with an
asterisk (*) next to it.

Checking • Run git branch -r to list branches stored on


Remote GitHub.
Branches: • Helps verify branches shared with the team.
GitHub Copilot – AI-Powered Coding
Introduction to GitHub Copilot
What Is GitHub Copilot?
An AI-powered coding assistant developed by GitHub Helps developers write code faster with intelligent
and OpenAI. suggestions.

How GitHub Copilot Works:


Suggests entire functions, snippets, and code
Uses machine learning to analyze code context.
completions.

Benefits of GitHub Copilot:


Increases coding efficiency by automating repetitive Reduces syntax errors by providing accurate
tasks. suggestions.
Setting Up GitHub Copilot in VS Code
Prerequisites for Installation: Installing Copilot Extension:
• A GitHub account with Copilot • Open VS Code and go to Extensions
enabled. Marketplace.
• Visual Studio Code installed on your • Search for GitHub Copilot and click
system. Install.

Activating GitHub Copilot:


• Sign in with GitHub and enable
Copilot in settings.
• Ensure Copilot is turned on for real-
time code suggestions.
Writing Code with Copilot (Examples & Hands-on)
How Copilot Assists in Coding:

• Suggests entire functions, loops, and syntax completions.


• Generates code based on comments and existing patterns.

Example of Copilot in Action:

• Writing a Python function by starting with a comment.


• Automatically generating boilerplate code for repetitive tasks.

Hands-On Practice Tips:

• Experiment with different prompts to refine suggestions.


• Review all generated code before using it in projects.
Copilot Best Practices & Limitations
• Provide meaningful comments to guide Copilot’s
Best Practices for suggestions.
Using Copilot: • Verify and modify generated code to match project needs.

Limitations of • May produce incorrect or insecure code in some cases.


Copilot: • Does not replace human judgment and debugging skills.

• Use Copilot for repetitive tasks but review critical logic.


Optimizing Copilot
• Combine AI assistance with manual coding for best
Usage: results.
Enabling GitHub Copilot in Different Programming
Languages
Supported Configuring Copilot Optimizing
Programming for Different Language-Specific
Languages: Languages: Suggestions:
• Works with Python, • Automatically • Use relevant
JavaScript, Java, detects language comments to get
C++, and more. from the file precise
• Supports web extension. recommendations.
development, • Customize behavior • Adjust Copilot
backend, and in VS Code settings settings to refine
scripting languages. for better code structure and
suggestions. format.
Understanding How Copilot Suggests Code
• Reads existing code and comments
How Copilot Analyzes for pattern recognition.
Context: • Uses deep learning models trained
on open-source code.
• The file’s language, structure, and
Factors Affecting Code coding patterns.
Suggestions: • Previous lines of code and common
industry practices.
• Writing clear and structured code
Improving Suggestion improves Copilot’s predictions.
Accuracy: • Experimenting with different prompts
enhances output quality.
Using Copilot for Repetitive Coding Tasks
• Auto-generates boilerplate code like loops and function
How Copilot templates.
Handles
Repetitive Tasks: • Suggests commonly used patterns based on previous
inputs.

Examples of • Automating API requests with predefined formats.


Repetitive Code • Generating SQL queries or data processing functions
Generation: efficiently.

• Reduces time spent on repetitive coding but requires


Improving validation.
Efficiency with
Copilot: • Works best for routine tasks while complex logic needs
manual review.
Common Errors and Fixes When Using Copilot
Frequent
How to Fix Best Practices
Issues with
Copilot Errors: to Avoid Errors:
Copilot:

Use Copilot as a
Generates incorrect Always review code
guide, not a
logic or inefficient before using it in
replacement for
code. production.
coding skills.

Keep up with
May suggest Test and debug AI-
programming best
outdated or insecure generated code to
practices to validate
coding practices. ensure correctness.
AI suggestions.
Privacy and Security Considerations with Copilot

Data Privacy Concerns:


Security Best Practices:
Copilot is trained on public
code but does not access Responsible Use of Copilot:
private repositories. Review suggestions to
ensure compliance with
Users should avoid security guidelines. Always validate AI-
inputting sensitive generated code before
information into AI- Avoid using Copilot- deploying.
generated code. generated credentials, keys,
or hardcoded data. Follow organizational
policies when using Copilot
in professional
environments.
GitHub Discussions & Further
Learning
Understanding GitHub Discussions
What Are GitHub Discussions?
• A forum-style feature for open conversations in repositories.
• Allows developers to ask questions, share ideas, and collaborate.

Key Features of GitHub Discussions:


• Supports threaded conversations for structured discussions.
• Enables upvoting, commenting, and marking answers as solutions.

Why Use GitHub Discussions?


• Encourages knowledge sharing within a project’s community.
• Helps developers find solutions and best practices.
Creating a Discussion Thread in GitHub
• Navigate to the Discussions tab in a repository.
How to Start a New
• Click “Start a New Discussion” and choose a
Discussion: category.

• Use a clear and descriptive title for the topic.


Posting an Effective
• Provide context and details to help others understand
Discussion: the discussion.

• Users can edit, close, or pin important discussions.


Managing
• Repository maintainers can moderate and organize
Discussion Threads: discussions.
Engaging with the Developer Community
Why Engage in Discussions?

• Helps developers learn from shared experiences.


• Builds connections with open-source contributors.

Ways to Participate in Discussions:

• Ask questions or share insights on relevant topics.


• Provide helpful answers to support other developers.

Best Practices for Community Engagement:

• Be respectful and constructive in responses.


• Follow repository guidelines when posting or commenting.
Upvoting and Commenting on Discussions
What Is Upvoting Improving
Commenting on
in GitHub Discussion
Discussions:
Discussions? Visibility:

Allows users to Share additional Upvoting useful


highlight helpful or insights or solutions answers makes them
important topics. in the thread. easier to find.

Engage in
Helps prioritize Commenting keeps
meaningful
discussions that discussions active
discussions by
benefit the and encourages
responding to
community. collaboration.
queries.
Following Important Discussions in Repositories
• Stay updated on important conversations in a project.
Why Follow
• Track discussions related to bugs, features, or best
Discussions? practices.

• Click “Subscribe” on a discussion thread to receive


How to Follow a updates.
Discussion: • Enable notifications for new replies and activity.

• Unsubscribe from threads that are no longer relevant.


Managing Followed
• Customize GitHub notification settings to reduce
Discussions: email clutter.
Reporting Inappropriate Content in Discussions
Why Report Discussions?
• Ensures a respectful and professional community.
• Helps moderators maintain a safe discussion environment.

How to Report Content:


• Click “Report” on a discussion or comment.
• Select the reason, such as spam, harassment, or misinformation.

Role of Moderators in Content Management:


• Review reported content and take necessary actions.
• Warn or ban users violating community guidelines.
Best Practices for Effective Discussions
• Use clear and descriptive titles for discussion threads.
Creating Valuable
• Provide enough context and examples when asking
Discussions: questions.

Engaging in • Stay respectful and provide constructive feedback.


Meaningful • Acknowledge helpful responses by upvoting or marking
Conversations: as solved.

• Avoid posting duplicate topics by searching first.


Maintaining
• Keep discussions relevant and avoid off-topic
Discussion Quality: conversations.
Exploring GitHub Learning Resources
Official GitHub Community and
Improving
Learning Open-Source
GitHub Skills:
Platforms: Resources:

GitHub Docs:
GitHub Discussions
Detailed Experiment with
& Forums: Learn
documentation on GitHub features in
from real-world use
Git and GitHub personal projects.
cases.
features.

GitHub Skills: Developer Blogs &


Contribute to open-
Interactive learning Tutorials: Stay
source repositories
courses for updated on best
to gain hands-on
beginners and practices and new
experience.
advanced users. features.
Git tracks file changes using staging, committing, and version
history.
Commit history provides a detailed record of project modifications.

Pushing updates syncs local code with the remote repository.

Summary Fetching and pulling updates ensure the latest code is available.

Branching allows isolated feature development without affecting the


main code.
GitHub Copilot enhances coding speed with AI-driven suggestions.

Discussions in GitHub help developers collaborate and share


knowledge.
GitHub learning resources offer documentation and interactive
tutorials.
Thank you for
listening!
Feel free to send in any questions
to [email protected].

You might also like