GitHub Basics for Version Control
GitHub Basics for Version Control
8311
Instructor:
▪ Eric Maniraguha | [email protected] | LinkedIn Profile
6h00 pm – 9h50 pm
▪ Monday A -G207
▪ Tuesday B-G204
▪ Wednesday E-G207 January 2024
▪ Thursday F-G307 1
GitHub: Where your
code meets its social
network!
2
GitHub
Reference reading
▪ YouTube Tutorial: Git Tutorial for Beginners: Learn Git in 1 Hour
▪ GitHub and Git Tutorial for Beginners
▪ Introduction to GitHub
▪ Intro to GitHub for version control
▪ DevOps Tools Mapping
▪ How to Design an Attractive GitHub Profile Readme…
▪ YouTube Tutorial: How to create Professional Github Readme Profile (Step By Step)
▪ Getting Started with R Markdown
▪ YouTube Tutorial: Git Merge Conflicts | How Merge Conflicts Happen | How to resolve
Merge Conflicts | Merge Conflict
▪ Git & GitHub
Course
Overview This course is designed to introduce students
to GitHub, a powerful platform for version
control and collaboration. Students will
learn the basics of using GitHub, including
creating repositories, committing
changes, branching, merging, and
collaborating with others. By the end of
the course, students will be comfortable using
GitHub for their projects.
4
5
What You’ll Learn
Leverage GitHub
Collaborate on Learn how to fork
Understand Git Create and tools like Issues,
projects using pull repositories and Write effective
and how it powers manage Labels, and
requests and contribute to open README files.
GitHub. repositories. Projects to
reviews. source.
organize tasks.
Use branches to
Track changes, Maintain clean
work on new Use Actions for Implement team
revert code, and Resolve conflicts code and
features without automated workflows and
create meaningful effectively. meaningful
affecting the main workflows. CI/CD pipelines.
commit histories. commit messages.
project.
6
▪ Developers and data scientists seeking collaboration skills.
▪ Students working on team projects.
▪ Professionals aiming to enhance productivity and code management.
Requirements:
▪ Basic knowledge of programming.
▪ A GitHub account.
7
Basic GitHub Terms
Repository (Repo):
A storage location for your project files, similar to a folder, where all the code, resources, and version history for your project are kept.
Branch:
A version of the repository used to develop new features without affecting the main (default) codebase.
Commit:
A snapshot of your changes in the repository, like saving progress with a message describing what was changed.
Push:
Sending your committed changes from your local repository to the remote repository on GitHub.
Pull:
Fetching and merging changes from the remote repository to your local repository.
Pull Request (PR):
A request to merge changes from one branch to another, often used for code review and collaboration.
Fork:
A personal copy of someone else's repository, allowing you to experiment or contribute to their project without affecting the original repository.
Clone:
Creating a copy of a GitHub repository on your local computer.
8
Basic GitHub Terms
Repository (Repo):
A storage location for your project files, similar to a folder, where all the code,
resources, and version history for your project are kept.
Branch:
A version of the repository used to develop new features without affecting the
main (default) codebase.
Commit:
A snapshot of your changes in the repository, like saving progress with a
message describing what was changed.
Push:
Sending your committed changes from your local repository to the remote
repository on GitHub.
Pull:
Fetching and merging changes from the remote repository to your local
repository.
Pull Request (PR):
A request to merge changes from one branch to another, often used for code
review and collaboration.
Fork: Source Image: https://medium.com/@derya.cortuk/git-terminology-101-366db34f1f4f
A personal copy of someone else's repository, allowing you to experiment or
contribute to their project without affecting the original repository.
Clone:
Creating a copy of a GitHub repository on your local computer.
9
Git and Command Line Terms
Terminal or Command Line (CLI):
An interface for entering text commands to interact with your computer or GitHub.
CLI (Command Line Interface):
A text-based interface used to execute Git commands like git add, git commit, and git
push.
Directory:
A folder in your file system where your project files are stored.
Working Directory:
The directory on your computer where your repository files are currently located.
Staging Area:
A temporary area where changes are stored before committing them to the
repository.
Merge:
Combining changes from different branches into a single branch.
HEAD:
Refers to the current branch you are working on in your repository.
Branches Parallel versions of a repository for development or testing. Work on features independently without affecting the main branch.
Pull Requests (PRs) Propose changes from one branch to another for review. Collaboration, code review, and merging changes.
Issues Tracks bugs, feature requests, and tasks. Bug reporting, task management, and feature planning.
GitHub Actions Automates workflows like CI/CD, testing, and deployments. Automatically run tests, build code, or deploy applications.
GitHub Pages Hosts static websites directly from a repository. Create project documentation, personal portfolios, or simple websites.
Wiki Documentation space for project guides and instructions. Maintain detailed project explanations and collaboration instructions.
Projects Kanban-style boards to visually track tasks and progress. Organize tasks for teams using Issues and Pull Requests.
Labels Tags to categorize Issues and Pull Requests. Mark tasks as bug, enhancement, or help wanted for better organization.
GitHub Marketplace Tools and integrations to enhance workflows. CI/CD tools, security scans, and project management plugins.
Security Features Tools like Dependabot and code scanning to ensure code safety. Identify and fix vulnerabilities in the codebase.
Gists Simple sharing of code snippets or text. Share small code samples, notes, or configurations.
Collaborators Add people to your repository with controlled access permissions. Invite team members to contribute directly to private projects.
Insights Analytics about code activity, contributors, and project history. Monitor code frequency, contributor activity, and Pull Request timelines.
GitHub Codespaces Cloud-based, pre-configured development environments. Start coding immediately without needing local setup.
12
Version Control Terms
A system that tracks changes to files over time, allowing you to recall specific versions later.
Distributed VCS:
A system like Git that allows multiple developers to work on the same codebase independently.
Remote Repository:
Local Repository:
Conflict:
A situation where changes from different branches or contributors overlap and need manual resolution.
13
Unlocking Git: Understanding Commands
Through Diagrams
1 2 14
How to get started
Please register on the GitHub website.
▪ On your computer, you need to install Git first. The process will depend on your operating system: please follow the instructions below by clicking the relevant button.
15
The basic commands include
Basic Commands initializing the Git repository,
saving changes, checking logs,
pushing the changes to the
remote server, and merging.
16
Command Description
git init Create a Git repository in a local directory.
git clone <url> Copy the entire repository from a remote server to a local directory. Can also clone local repositories.
git add <file.txt> Add a single file or multiple files and folders to the staging area.
git commit -m "Message" Create a snapshot of changes and save it in the repository.
git config Set user-specific configurations like email, username, and file format.
git status Show the list of changed files or files that have yet to be staged and committed.
git push <remote-name> <branch-name> Send local commits to the remote branch of the repository.
git remote add <remote-name> <host-or-remoteURL> Add a remote server to the local repository.
git pull Merge commits from a remote repository into a local directory.
git merge <branch-name> After resolving merge conflicts, blend the selected branch into the current branch.
17
git log Show a detailed list of commits for the current branch.
Mastering Markdown for GitHub
What is Markdown?
Why Learn Efficiency: Quick and simple syntax.
▪ A lightweight maarkup language to format plain text. Markdown?
▪ Used for documentation, README files, and wikis on GitHub. Versatility: Powers README files, GitHub Pages, and wikis.
Markdown text 19
What is a GitHub User Profile?
A GitHub user profile is a public page that represents a user's identity on GitHub. It shows information about the user, their
repositories, contributions, and activities.
Profile Picture and Bio Profile Picture: A photo or avatar to represent the user (optional).
Bio: A short description about the user, such as their role, interests, or expertise.
Pinned Repositories Highlight important repositories the user wants to showcase, such as personal projects or open-source
contributions.
Contribution Graph A heatmap showing the user's contributions (commits, pull requests, issues) over the past year.
Repositories A list of all public repositories owned by the user, including the name, description, and programming languages
used.
Followers and Following Followers: People who are subscribed to the user's updates.
Following: Other GitHub users the profile owner is following.
Activity Feed Displays recent activities such as commits, pull requests, and discussions.
GitHub README Profile A custom section created by adding a README.md file in a repository named after the user’s username.
(Optional)
This can include skills, achievements, current projects, or links to portfolios.
Organizations Lists any organizations the user is a part of on GitHub.
Gists A list of code snippets or text files the user has shared publicly or privately.
Source Image: Profile readme
20
How to Enhance Your GitHub Profile
Use a Profile README: Create a repository named after your username (e.g., username/username) and add a README.md file with
personalized content.
Customize Your Bio: Include links to your portfolio, LinkedIn, or website. Use emojis and markdown for a visually appealing bio.
Pin Repositories Strategically: Highlight projects that showcase your skills and achievements.
Stay Active: Regularly contribute to repositories, create new projects, or maintain existing ones.
Engage with the Community: Participate in discussions, report issues, or contribute to other repositories.
A GitHub profile acts as a professional portfolio that demonstrates your skills and contributions, making it valuable for recruiters,
collaborators, and the developer community.
21
GitHub User Profile
Adding a profile README
In the upper-right corner of any page, select + , then
click New repository.
22
Removing a profile README
The profile README will be removed from your GitHub profile if any of the following apply:
The method you choose depends upon your needs, but if you're unsure, we recommend making your
repository private. For steps on how to make your repository private, see " Setting repository visibility."
23
Step I. Create your own repository
24
Step II. Create your own repository
Initialize Repo:
▪ Create a README.md for project details, purpose,
and licensing.
Markdown Format:
▪ Use .md for structured project documentation.
.gitignore File:
▪ Exclude unnecessary files from the repo.
Language Template:
▪ Select the relevant template (e.g., R) in the
.gitignore.
25
Created Repository
26
Repository is created
Explanation:
▪ echo "# my-first-repository" >> README.md: This creates a new README.md file with a simple
title inside it.
▪ git init: Initializes a new Git repository in your current directory.
▪ git add README.md: Stages the README.md file for committing.
▪ git commit -m "first commit": Commits the staged file with the message "first commit."
▪ git branch -M main: Renames the current branch to main.
▪ git remote add origin <url>: Links the local repository to a remote GitHub repository.
▪ git push -u origin main: Pushes the code from the local main branch to the remote main branch and
sets up tracking between the two.
Use case: This method is useful when you're starting from scratch and want to create a new Git
repository, initialize it, and then push it to GitHub.
Explanation:
▪ git remote add origin <url>: Links the local repository to the remote GitHub repository.
▪ git branch -M main: Renames the branch to main (if it hasn't been done already).
▪ git push -u origin main: Pushes the local branch to the remote repository and sets up the tracking.
Use case: This method assumes that you've already initialized a Git repository, committed your changes,
and just want to push an existing repository to GitHub.
27
Why “.gitignore”?
The .gitignore file is essential because it tells Git which files or directories to ignore in a project.
▪ Keep Repositories Clean: Exclude unnecessary files (e.g., temporary files, build artifacts) from being tracked by Git.
▪ Protect Sensitive Information: Prevent sensitive data (e.g., API keys, passwords) from being accidentally committed.
▪ Optimize Collaboration: Ensure that only relevant files are shared among team members, reducing clutter and potential conflicts.
▪ Maintain Efficient Version Control: Focus on tracking and managing only the files that are important to the project.
1. log/*.log.[0-9]
▪ This ignores files in the log/ directory that have the format *.log.[0-9].
▪ For example:
o log/error.log.1
o log/output.log.2
▪ These files are likely log rotation files (e.g., created when logs are rotated to manage size).
2. assests/video/
▪ This ignores everything inside the assests/video/ directory.
▪ All files and subdirectories within assests/video/ will be excluded from Git.
3. !assests/video/iphone_*.mp4
▪ The ! negates the ignore rule, meaning it will include files matching the pattern
assests/video/iphone_*.mp4, even though the assests/video/ directory is ignored.
▪ Only files named like iphone_video.mp4, iphone_clip.mp4, etc., will be tracked by Git.
28
How to create a git repository?
Here is how the repository should look:
29
GIT Push and Pull Tutorial
Note: Create a new repository like the previous slide as the 1st step
30
GIT Push and Pull Tutorial
5. Add the file to the new local repository 6. Commit the files staged in your local repository
by writing a commit message
31
GIT Push and Pull Tutorial
7. Copy your remote repository's URL from GitHub
▪ The HTTPS or URL is copied from the given GitHub account, which is the place of the remote repository.
8. Add the URL copied, which is your remote repository to where your local content from your
repository is pushed
32
GIT Push and Pull Tutorial
9. Push the code in your local repository to GitHub
▪ git push -u origin master is used for pushing local content to GitHub.
▪ In the code, the origin is your default remote repository name and '-u' flag is
upstream, which is equivalent to '-set-upstream.' and the master is the branch,
name.upstream is the repository that we have cloned the project.
▪ Fill in your GitHub username and password.
33
Git Push and Pull Tutorial
10. View your files in your repository hosted on GitHub
34
Challenge Yourself!
Elevate Your GitHub Expertise: Master Branching, Collaboration, and Conflict Resolution
Enhance Code
Integration: Improve your
skills in integrating code
Resolve Conflicts: from various sources to
maintain a cohesive and
Master conflict resolution high-quality project.
techniques to handle and
Form Groups: merge conflicting changes
Learn how to organize and smoothly.
collaborate within groups on
Manage Team Projects: GitHub.
Understand how to set up
and manage team projects
Create Branches: for collaborative
Learn how to create and development.
manage branches to work
on different features or fixes
simultaneously.
35
Career Opportunities with GitHub Skills: Unlocking Roles in
Development, Data, and More
37
Keep Learning!
38