Ultimate Git and GitHub Tutorial with Examples

05 August 2024 | 51 min read

In software development, Git and GitHub have become essential tools for managing and collaborating on code. In this guide, we'll learn how to use Git, a powerful version control system, and GitHub, the leading platform for hosting and sharing Git repositories.

We will start by discussing Git and its most important terms. We'll cover basic Git commands and approaches and then move on to GitHub. Finally, we'll explore commands to work with GitHub repositories and answer some common questions. By the end of this article, you'll be familiar with both Git and GitHub and all the standard approaches. So, let's get started!

Prerequisites

Before diving into the world of Git and GitHub, you'll need the proper equipment:

  1. Command Line Interface (CLI) Tool: You'll need a terminal or command line interface to run Git commands. Most operating systems come with a built-in terminal:
    • Windows: Command Prompt or PowerShell. Alternatively, you can install Git Bash, which provides a Unix-like environment.
    • macOS: Terminal application.
    • Linux: Terminal application.
  2. Web Browser: You'll need a web browser to access GitHub and other Git hosting platforms. Popular browsers include Chrome, Firefox, Safari, and Edge.
  3. Git Installed: Ensure you have Git installed on your computer. Details on how to install Git are in the next section.

How to install Git

You can download and install Git from the official website . Simply choose a version for your operating system and follow the instructions.

Additionally, you can use GUI clients for Git that might be more convenient and easy to use. However, in this article, we'll focus on working with Git via CLI.

To check that Git is installed, restart your command-line interface and type:

git -v

If you see something like git version 2.45.2.windows.1, it means that Git has been successfully installed.

What is Git?

To put it simply, Git is a version control system. I like the analogy "Git is a save button for your code but on steroids". It helps you track changes, manage collaboration, and maintain a history of your project.

Why is Git helpful?

Imagine you're working on an important document and accidentally delete a crucial section. Without a way to track changes, you'd have a hard time restoring it. Git solves this problem for code and does much more.

Here's why Git is so useful:

  • Track Changes: Every change you make to the project is recorded. Picture this: you've been working on a feature for days, and suddenly, you realize you've deleted a critical part of your code by mistake. With Git, you can easily revert to a previous version and restore what was lost. It's like having an undo button that never forgets.
  • Collaboration: Ever tried working on a project with a team where everyone is editing the same files? It can quickly become chaotic. Git allows multiple developers to work on the same project simultaneously without stepping on each other's toes. Each team member can work on their own branch and merge changes together, ensuring everyone's contributions are integrated smoothly.
  • Backup: I'm sure you know the dread of a computer crash. Without proper backups, you risk losing days, weeks, or even months of work. Git enables you to store data in multiple locations, providing a safety net. If something goes wrong with your machine, your code is still safe on the remote repository.
  • Branching: Experimenting with new features or ideas is crucial in development, but you don't want to risk breaking the main project. With Git, you can create a branch to work on new features in isolation. If the experiment works out, you can merge it back into the main project. If not, you simply delete the branch without any impact on the main codebase.

So one could say that Git is like the version history feature in Google Docs but more advanced and tailored for code. It keeps a detailed log of every change, making it easy to track, revert, and collaborate on projects.

What is GitHub?

GitHub is a web-based platform that serves as a hosting service for Git repositories. It provides a collaborative environment where developers can store, manage, and share their code. GitHub implements Git but makes it easier to perform common actions and work on projects both individually and as part of a team.

Why is GitHub helpful?

  • Repository hosting: GitHub hosts your Git repositories in the cloud, making them accessible from anywhere. Each repository comes with tools for managing and tracking changes.
  • Collaboration tools: GitHub offers a range of features to enable collaboration, including pull requests, code reviews, and issue tracking. These tools help teams discuss changes, review code, and manage project tasks efficiently.
  • Project management: With features like Projects, Issues, and Milestones, GitHub allows you to organize and prioritize work. These tools are simpler versions of solutions like Trello and Asana.
  • Continuous integration and deployment: GitHub Actions enables you to automate workflows, such as running tests, building your project, and deploying code. This powerful feature allows you to write custom instructions for tasks when your project is updated or a new version is released.
  • Community and open source: GitHub hosts millions of open-source projects, providing a space for developers to collaborate, contribute, and learn from each other.
  • Documentation and wikis: GitHub allows you to create detailed documentation and wikis for your projects. This helps in maintaining comprehensive guides, tutorials, and project details for users and contributors.

As you can see, GitHub is more than just a repository hosting service. It's a platform packed with solid features that you can start using for free. In fact, to me is seems that GitHub has become a proto-social network for developers, though without the ability to post short messages or photos. Here's why:

  • User interaction: Developers can follow each other, star repositories, and watch projects. These interactions are similar to how users engage on social networks.
  • Collaborative features: GitHub provides tools like pull requests, code reviews, and discussions. These features facilitate collaboration and community engagement, similar to social media interactions.
  • Profile and activity feeds: Users have profiles showcasing their contributions, repositories, and activity feeds. This public display of work and activity fosters a community where developers can discover and connect with each other.
  • Networking opportunities: GitHub is often used for networking, where developers can find and connect with potential collaborators, employers, or peers based on their projects and contributions. It's like LinkedIn for geeks.

Is Git the same as GitHub?

No, Git and GitHub are not the same, though they are often used together!

  • Git is a distributed version control system. It helps you track changes in your code and manage different versions. It operates on your local machine, enabling you to create repositories, make commits, branch out for new features, and merge changes back together. You don't need internet access to work with Git, and you can work alone or within a team.
  • GitHub is a web-based platform that hosts Git repositories in the cloud, making them accessible from anywhere. It provides a visual interface and additional features to make using Git easier and more collaborative. Specifically, GitHub adds features like pull requests, forking, issue tracking, project management tools, and more.

Other platforms like GitHub

While GitHub is one of the most popular platforms for hosting Git repositories, there are several other options available:

  • GitLab: Similar to GitHub, GitLab offers Git repository hosting with additional features like built-in CI/CD (Continuous Integration/Continuous Deployment) pipelines.
  • Bitbucket: Another Git repository hosting service that integrates well with Atlassian tools like Jira and Trello, making it a great option for teams already using these products.
  • SourceForge: An older platform that supports Git as well as other version control systems. It's known for hosting a wide range of open-source projects.

Key Git terms

Next, let's establish some important Git terminology that we'll use throughout the article. Feel free to skip this section for now and return to it when you encounter an unknown term.

What is a Git repository (repo)?

A repository is like a project's folder. It contains all the project files and the entire history of changes made to those files. Repositories can be local (on your computer) or remote (hosted on platforms like GitHub).

What is the working directory?

The working directory is where you make changes to your project files. It's the current state of your project that you see in your file system.

What is the staging area (index)?

The staging area is a place where you prepare changes before committing them. When you make changes in your working directory, you need to add them to the staging area. Think of it as a buffer zone where you decide which changes should be included in the next commit.

Before making a commit, you can continue to modify the staging area by adding more changes, removing changes, or organizing them as needed.

What is a commit?

Remember those instant Polaroid cameras people used in the '90s? A commit is like an instant photo or a snapshot of your project at a specific point in time. It records changes to the repository and creates a checkpoint that you can return to later, just like you can view an old photo from your childhood.

Each commit has a unique ID and a message describing the changes. The commit includes only the changes that were staged in the staging area. This means you can work on several different changes in your working directory, stage only some of them, and then commit just those staged changes.

What is a branch?

A branch is a separate line of development or a separate version of the project, if you will. It allows you to work on new features or bug fixes independently from the main codebase. Initially, you have only a single branch that is typically named master or main.

Once the work on a branch is complete, it can be merged back into the main branch. However, if you don't like this project version, the corresponding branch can be safely removed.

What is a merge?

Merging is the process of combining changes from different branches into one branch. It integrates the work done on separate branches, resolving any conflicts that may arise.

What is a remote repository?

A remote repository is a version of your project that is hosted on the internet or another network. It allows you to share your project with others and collaborate. GitHub, GitLab, and Bitbucket are examples of platforms that host remote repositories.

What is a clone?

Cloning is the process of creating a local copy of a remote repository. Essentially, you are downloading all the files and the entire history of the project to your local machine.

What is a pull?

Pulling is the process of fetching changes from a remote repository and merging them into your local repository. It updates your local copy with the latest changes from the remote source, whereas cloning fully downloads the chosen repository.

What is a push?

Pushing is the process of uploading your local changes to a remote repository. It updates the remote repository with your latest commits.

What is a conflict?

A conflict occurs when changes from different branches clash and Git cannot automatically merge them. Conflicts usually need to be resolved manually by the developer.

What is HEAD?

HEAD is a reference to the latest commit in the current branch. It points to the snapshot that is currently checked out in your working directory.

How to use Git: Basic Git commands and approaches

In this section, we're going to cover the most widely used Git commands that you should be aware of.

How to configure Git username and email: git config

The git config command is used to set configuration options for Git. Two important options to set are your username and email, which are used to identify the author of commits.

What git config does

When you run git config, Git updates its configuration settings to include the specified username and email. These details are then included in the metadata for each commit you make, identifying you as the author.

How to use git config

To configure your Git username and email, you use the git config command in your CLI followed by the option you want to set. Here's the basic syntax:

  • How to set Git username:
git config --global user.name "Your Name"
  • How to set Git email:
git config --global user.email "your.email@example.com"

Typically, you run these two commands once after installing Git. To make sure everything has been configured properly, execute:

git config --global --list

This will display your current Git configuration, including the username and email you just set.

Local vs global configuration

  • Global configuration: The --global flag sets the configuration for all repositories on your system. The configuration settings are stored in the ~/.gitconfig file.
  • Local configuration: To set the configuration for a specific repository, navigate to that repository and run the git config command without the --global flag. These settings are stored in the repository's .git/config file.

How to create a Git repository: git init

The git init command is used to initialize a new Git repository locally. This command sets up the necessary files and directories for Git to start tracking changes in your project. It's the first step to using Git in a new or existing project.

What git init does

When you run git init, Git performs the following actions:

  • Creates a hidden .git directory in the root of your project. This directory contains all the metadata and repository history for Git to track your project. It basically means that you should be very careful with the .git folder because if it's removed, all local history will be lost.
  • Sets up the necessary files and directories for Git to operate.

After running git init, your project directory is now a Git repository, and Git will start tracking changes you make to the files within it.

How to use git init

To initialize a new Git repository, navigate to the root directory of your project in your terminal and run the following command:

git init

How to add changes to the staging area: git add

The git add command is used to add changes in your working directory to the staging area. This command tells Git which changes you want to include in your next commit. You can add individual files, directories, or all changes at once.

What git add does

When you run git add, Git stages the changes you've specified. This means Git is preparing these changes to be included in the next commit. The changes aren't saved to your repository's history until you run git commit.

How to use git add

To add changes to the staging area, you use the git add command followed by the file or directory you want to stage. Here are some common usages:

  • How to add a specific file:
git add filename
  • How to add all changes in the current directory:
git add .
  • How to add all changes in the entire project:
git add -A

Tracked and untracked Files

In Git, files in your working directory are classified as either tracked or untracked.

Tracked files

Tracked files are files that Git is aware of and is tracking for changes. These files were part of your last commit and will be included in future commits if they are modified.

Untracked files

Untracked files are files in your working directory that Git is not yet tracking. These files were not part of your last commit and need to be added to the staging area if you want Git to track them.

How to track a file

To start tracking a file, you need to add it to the staging area using the git add command. Here's how you can do it:

  • How to track a specific file:
git add filename
  • How to track all untracked files in the current directory:
git add .

How to undo git add

If you want Git to stop tracking a file that it has previously tracked, you need to remove it from the staging area and the repository history. Here's how you can do it:

  • How to untrack a specific file:
git rm --cached filename

This command removes the file from the staging area but keeps it in your working directory.

How to ignore and unignore files in Git

The .gitignore file typically located in the project root is used to tell Git which files or directories to fully ignore and never track. This is useful for files that are generated automatically, contain sensitive information, or are specific to your development environment.

Here are some common .gitignore examples:

  • How to ignore all .log files:
*.log
  • How to ignore all files in the temp directory:
temp/
  • How to ignore a specific file:
secret_config.txt
  • How to ignore all .DS_Store files (common on macOS):
.DS_Store
  • How to ignore all files in the node_modules directory (common for Node.js projects):
node_modules/

To create a .gitignore file, simply add the patterns of files and directories you want to ignore, and save the file in the root directory of your repository. Git will automatically respect these rules and ignore the specified files and directories.

How to view the state of the working directory: git status

The git status command is used to display the state of the working directory and the staging area. It shows which changes have been staged, which haven't, and which files aren't being tracked by Git.

What git status does

When you run git status, Git provides information on:

  • Staged changes: Files that are ready to be committed.
  • Unstaged changes: Files that have been modified but not yet staged.
  • Untracked files: Files in the working directory that are not being tracked by Git.

This command is helpful for understanding the current state of your project and deciding what actions to take next, such as staging changes or committing updates.

How to use git status

To check the status of your repository, simply run the following command in your terminal:

git status

You will see an output that lists the staged changes, unstaged changes, and untracked files. Here's an example of what the output might look like:

On branch main
Your branch is up to date with 'origin/main'.

Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: file1.txt
new file: file2.txt

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: file3.txt

Untracked files:
(use "git add <file>..." to include in what will be committed)
file4.txt
  • Changes to be committed: These are the files that have been staged and are ready to be committed.
  • Changes not staged for commit: These are the files that have been modified but not yet staged.
  • Untracked files: These are new files that are not being tracked by Git.

How to create a commit: git commit

The git commit command is used to save your changes to the local repository. When you commit, you record a snapshot of the changes in the staging area, adding them to the project's history.

What git commit does

When you run git commit, Git:

  • Takes the changes in the staging area.
  • Records a snapshot of those changes in the repository.
  • Assigns a unique ID (hash) to the commit.
  • Associates a message with the commit, which helps describe what the commit does.

Each commit acts as a checkpoint in your project's history, allowing you to revert to previous states if needed. It’s important to write clear and descriptive commit messages to make it easier to understand the history of your project.

How to use git commit

To commit changes, you use the git commit command followed by a message describing the changes. Here are some common usages:

  • How to commit with a message:
git commit -m "Your commit message"
  • How to commit all changes directly (bypasses staging area):
git commit -a -m "Your commit message"

Tips for writing good commit messages

Writing clear and informative commit messages is crucial for maintaining a useful project history. Here are some tips:

  • Keep it short and sweet: A good commit message should be brief yet descriptive.
  • Use the imperative mood: This style makes your messages more consistent and easier to read. For example, "Add feature" instead of "Added feature".
  • Explain why, not just what: If the changes are complex, include a brief explanation of why the changes were made.

How to view commit history: git log

The git log command is used to display the commit history of a repository. It shows a list of all the commits made to the repository in reverse chronological order, with the most recent commits appearing first.

What git log shows

When you run git log, Git provides information on each commit, including:

  • Commit Hash: A unique identifier for each commit.
  • Author: The person who made the commit.
  • Date: The date and time when the commit was made.
  • Commit Message: A description of the changes made in the commit.

How to use git log

To view the commit history, simply run the following command in your terminal:

git log

You will see an output that lists the commits, showing information like this:

commit 1a2b3c4d5e6f7g8h9i0jklmnopqrstuvwx
Author: Your Name you@example.com
Date: Mon Jul 28 12:34:56 2024 -0700

Added new feature

commit 9z8y7x6w5v4u3t2s1r0qponmlkjihgfedcba
Author: Another Developer another@example.com
Date: Sun Jul 27 11:22:33 2024 -0700

Fixed a bug

Explanation of the output:

  • Commit Hash: A long string of letters and numbers (e.g., 1a2b3c4d5e6f7g8h9i0jklmnopqrstuvwx) that uniquely identifies the commit.
  • Author: The name and email of the person who made the commit.
  • Date: The exact date and time when the commit was made.
  • Commit Message: A brief description of what changes were made in the commit. This helps you understand the purpose of each commit at a glance.

Common options

The git log command has several options to customize the output:

  • How to show a single line per commit:
git log --oneline

This option condenses each commit to a single line, showing only the commit hash and the commit message. It's useful for getting a quick overview of the commit history.

  • How to limit the number of commits shown:
git log -n 5

This option limits the output to the most recent 5 commits. You can replace 5 with any number to adjust the limit.

  • How to show the history of a specific file:
git log filename

This option displays the commit history for a specific file, helping you track changes to that particular file over time.

  • How to display graphical representation of the commit history:
git log --graph --oneline

This option adds a graphical representation of the commit history, showing branches and merges in a simplified format.

How to see changes before commit: git diff

The git diff command can come in handy when you want to see changes in your code. It helps you track what you've modified, added, or deleted before you commit those changes.

What git diff does

git diff shows you the differences between various states of your repository. It can compare your working directory with the staging area, your staging area with the last commit, or even two different commits.

How to use git diff

  • How to see changes in the working directory that haven't been staged for commit:
git diff
  • How to see changes between the staging area and the last commit:
git diff --staged
  • How to compare two different commits:
git diff commit1_id commit2_id

git diff options

  • git diff --color: Highlights changes in color, making them easier to read.
  • git diff --name-only: Lists only the names of changed files.
  • git diff --name-status: Shows the names of changed files along with their status (added, modified, deleted).
  • git diff branch1..branch2: Compares differences between two branches.

Tips for using git diff

  • Combine with grep to filter results: git diff | grep "keyword".
  • Use git difftool for a more user-friendly interface, especially with GUI tools like meld.
  • Remember that git diff can be overwhelming in large projects. Use specific file paths to narrow down the output: git diff path/to/file.

How to revert a commit: git revert

The git revert command is used to create a new commit that undoes the changes made by a previous commit. This command is a safe way to undo changes because it doesn't alter the existing commit history.

What git revert does

When you run git revert, Git:

  • Creates a new commit that reverses the changes introduced by the specified commit.
  • Prompts you to enter a commit message for the revert commit, which by default includes information about the commit being reverted.

How to use git revert

To revert a commit, you use the git revert command followed by the commit hash of the commit you want to undo. Here's the basic syntax:

git revert <commit-hash>

To find the commit-hash, you can use the git log command explained above.

After running this command, Git will open a text editor to prompt you for a commit message. By default, it includes the message "Revert ". Adjust the message as needed, save, and close the text editor to complete the revert.

Example in practice

Imagine you have the following commits in your history:

commit 1a2b3c4d5e6f7g8h9i0jklmnopqrstuvwx
Author: Your Name you@example.com
Date: Mon Jul 28 12:34:56 2024 -0700

Added new feature

commit 9z8y7x6w5v4u3t2s1r0qponmlkjihgfedcba
Author: Another Developer another@example.com
Date: Sun Jul 27 11:22:33 2024 -0700

Fixed a bug

If you want to revert the commit that added the new feature (1a2b3c4d5e6f7g8h9i0jklmnopqrstuvwx), you would run:

git revert 1a2b3c4d5e6f7g8h9i0jklmnopqrstuvwx

This command creates a new commit that undoes the changes made by the specified commit, preserving the commit history. I can also recommend checking the following website that lists some typical scenarios when everything does wrong and how to fix them.

How to undo a commit: git reset

The git reset command is used to undo commits by moving the current branch to a specified commit. This command can be more powerful and potentially more dangerous than git revert because it changes the commit history.

How to use git reset

To perform a reset, run:

git reset --TYPE <commit-hash>

To find the commit-hash, you can use the git log command covered above. The --TYPE is explained below.

Types of git reset

  1. --soft
    • Moves the branch pointer to the specified commit.
    • Does not change the staging area or the working directory.
    • This effectively undoes commits but keeps your changes in the staging area.
git reset --soft <commit-hash>
  1. --mixed (default)
    • Moves the branch pointer to the specified commit.
    • Resets the staging area to match the specified commit.
    • Does not change the working directory.
    • This effectively undoes commits and unstages the changes.
git reset --mixed <commit-hash>
  1. --hard
    • Moves the branch pointer to the specified commit.
    • Resets the staging area and the working directory to match the specified commit.
    • This completely undoes commits and discards all changes in the working directory and staging area.
git reset --hard <commit-hash>

What git reset does

When you run git reset, Git adjusts the current branch to point to the specified commit. Depending on the type of reset you choose, it also affects the staging area and working directory. Here's a brief summary of each type:

  • Soft Reset: Keeps changes in the staging area.
  • Mixed Reset: Unstages the changes but keeps them in the working directory.
  • Hard Reset: Discards all changes in the staging area and working directory.

Why git reset is dangerous

The git reset command is powerful but can be dangerous, especially when using the --hard option. Here's why:

  • Data Loss: The --hard option discards all changes in your working directory and staging area. If you haven't backed up or committed these changes, they will be lost permanently.
  • History Rewriting: Resetting the commit history can cause confusion in collaborative environments, as it changes the commit history that others might be working with.

How to create and manage branches: git branch

The git branch command is used to manage branches in your repository. Branches allow you to work on different features, bug fixes, or experiments independently from the main codebase.

What git branch does

When you run git branch with different options, Git performs the following actions:

  • List branches: Displays all branches in the repository, highlighting the current branch with an asterisk (*).
  • Create branch: Creates a new branch with the specified name. This branch is a copy of the current branch at the time of creation.
  • Delete branch: Deletes the specified branch. Git will not allow you to delete the branch you are currently on.

How to use git branch

The git branch command has several uses, including listing, creating, and deleting branches. Here are some common usages:

  • How to list all branches:
git branch
  • How to create a new branch:
git branch branch-name
  • How to delete a branch:
git branch -d branch-name

Common options

The git branch command has several common options:

  • Force delete a branch:
git branch -D branch-name
  • Rename a branch:
git branch -m old-branch-name new-branch-name
  • List remote branches:
git branch -r
  • List all branches (local and remote):
git branch -a

How to switch branches: git checkout

The git checkout command is used to switch between branches or restore working directory files. It's a versatile command that can change the current branch, revert files to a previous state, or even create a new branch.

What git checkout does

When you run git checkout, Git performs the following actions based on the provided arguments:

  • Switch branch: Updates the working directory and staging area to match the specified branch. This operation changes the HEAD to point to the new branch.
  • Create and switch branch: Creates a new branch from the current HEAD and switches to it.
  • Restore file: Reverts the specified file to its state in the given commit. This can be useful for undoing changes to a particular file without affecting the rest of the working directory.

How to use git checkout

Here are some common usages of the git checkout command:

  • How to switch to an existing branch:
git checkout branch-name
  • How to create a new branch and switch to it:
git checkout -b new-branch-name
  • How to restore a file to its state in a specific commit:
git checkout commit-hash -- filename

The git checkout command is powerful but can be potentially confusing and disruptive, especially when used to switch branches. It's important to ensure that you have committed or stashed any changes in your working directory before switching branches to avoid losing work.

How to stash changes: git stash

The git stash command is used to temporarily save changes in your working directory that you are not ready to commit. This allows you to switch branches or work on something else without losing your progress.

What git stash does

When you run git stash, Git:

  • Saves the changes in your working directory and the staging area to a new stash entry.
  • Resets your working directory to match the HEAD commit, effectively making it clean.

How to use git stash

Here are some common usages of the git stash command:

  • How to stash changes:
git stash
  • How to list stashed changes:
git stash list
  • How to apply the most recent stash:
git stash apply
  • How to apply a specific stash:
git stash apply stash@{n}
  • How to apply and remove the most recent stash:
git stash pop
  • How to drop a specific stash:
git stash drop stash@{n}
  • How to clear all stashes:
git stash clear

Using git stash is very helpful when you need to temporarily set aside changes without committing them. It allows you to keep your working directory clean and switch contexts easily. However, remember that stashes are stored in a stack, so you need to manage them carefully to avoid confusion.

How to merge branches: git merge

The git merge command is used to combine changes from one branch into another.

What git merge does

When you run git merge, Git performs the following actions:

  • Integrates the specified branch into the current branch.
  • Creates a new merge commit if there are no conflicts, combining the histories of both branches.
  • If there are conflicts, Git will prompt you to resolve them before completing the merge.

How to use git merge

To merge changes from one branch into the current branch, you use the git merge command followed by the name of the branch you want to merge. Here's the basic syntax:

  • How to merge a branch into the current branch:
git merge branch-name

Merge types

  • Fast-forward merge: If the current branch has not diverged from the branch being merged, Git will perform a fast-forward merge, simply moving the branch pointer forward.
  • Three-way merge: If the branches have diverged, Git performs a three-way merge, combining the histories and creating a new merge commit.

Handling merge conflicts can be a bit tricky, but with practice, you'll become more comfortable resolving them and keeping your project history clean and organized.

How to resolve merge conflicts

Conflicts occur when changes in the branches being merged cannot be automatically reconciled. Here's how to handle merge conflicts:

  1. Git will mark the conflicted areas in the files.
  2. Open each conflicted file and manually resolve the conflicts.
  3. Stage the resolved files using git add.
  4. Complete the merge with git commit.

Example of a merge conflict

Imagine you have two branches: main and feature-branch. Both branches have made changes to the same part of a file called example.txt.

  1. Attempt to merge feature-branch into main:
git checkout main
git merge feature-branch
  1. Git detects a conflict and the example.txt file is marked with conflict markers:
<<<<<<< HEAD
Content from the main branch.
=======
Content from the feature branch.
>>>>>>> feature-branch
  1. Open example.txt in your editor to resolve the conflict. Decide which content to keep or combine them manually:

Content from the main branch. Content from the feature branch.

  1. Stage the resolved file:
git add example.txt
  1. Complete the merge:
git commit -m "Resolved merge conflict between main and feature-branch"

How to rebase: git rebase

The git rebase command is used to integrate changes from one branch into another. Unlike git merge, which preserves the complete history of commits from both branches, git rebase creates a linear history by moving or replaying commits from one branch onto another.

When to use git rebase

  • Feature branches: Rebase feature branches onto the main branch to create a clean, linear history before merging.
  • Updating branches: Rebase to update a branch with the latest changes from another branch without creating a merge commit.
  • Cleaning up commits: Use interactive rebase to edit, squash, or drop commits before sharing your branch.

How to use git rebase

To rebase changes from one branch onto another, you use the git rebase command followed by the name of the branch you want to rebase onto. Here's the basic syntax:

  • How to rebase the current branch onto another branch:
git rebase branch-name

How to squash and manage commits: interactive rebase

Interactive rebase allows you to edit, reorder, squash, or drop commits. This mode is useful for cleaning up commit history before merging a feature branch.

  • How to start an interactive rebase:
git rebase -i HEAD~n

Replace n with the number of commits you want to review and potentially edit.

Rebase example

  1. Switch to the branch you want to rebase:
git checkout feature-branch
  1. Rebase the current branch onto another branch (e.g., main):
git rebase main
  1. If there are no conflicts, Git will reapply your commits onto the main branch and complete the rebase.
  2. If there are conflicts, Git will stop and prompt you to resolve them. After resolving conflicts, you can continue the rebase:
git add resolved-file
git rebase --continue
  1. If you want to abort the rebase and return to the original state, use:
git rebase --abort

Interactive rebase example

Here's how to use interactive rebase to clean up your commit history:

  1. Start an interactive rebase for the last 3 commits:
git rebase -i HEAD~3
  1. An editor will open with a list of the last 3 commits:
pick 1a2b3c4 Commit message 1
pick 2b3c4d5 Commit message 2
pick 3c4d5e6 Commit message 3
  1. Change pick to edit, squash, or drop to modify the commits:
pick 1a2b3c4 Commit message 1
squash 2b3c4d5 Commit message 2
drop 3c4d5e6 Commit message 3
  1. Save and close the editor. Follow the prompts to edit, squash, or drop the commits as specified.
  2. If you chose to edit a commit, Git will pause and allow you to make changes. After editing, continue the rebase with:
git commit --amend
git rebase --continue
  1. If you chose to squash commits, Git will combine them into a single commit. You will be prompted to edit the commit message.

How to manage rebase conflicts

Conflicts can occur during a rebase, just like during a merge. Here's how to handle them:

  1. Git will pause and mark the conflicted areas in the files.
  2. Open each conflicted file and manually resolve the conflicts.
  3. Stage the resolved files using git add.
  4. Continue the rebase with git rebase --continue.
  5. If you encounter more conflicts, repeat the process until the rebase is complete.

git rebase vs git merge

Both git rebase and git merge are used to integrate changes from one branch into another, but they do so in different ways and have distinct use cases.

TL;DR

  • Use git merge when you want to combine branches while preserving the full history.
  • Use git rebase when you want to create a linear history, cleaning up the commit sequence before merging into the main branch.

git merge

  • Preserves history: git merge combines the histories of two branches, preserving the commits from both branches. This creates a merge commit that has two parent commits.
  • Non-destructive: The original branches remain unchanged, and no commits are lost.
  • Commit graph: The commit graph remains branched, showing the true history of the project with all branches and merges.

git rebase

  • Rewrites history: git rebase moves or replays commits from one branch onto another, creating a linear history. The original commits are replaced by new commits with the same changes but different hashes.
  • Destructive: The original commits are discarded, and new commits are created. This can cause issues if others are working on the same branch.
  • Commit graph: The commit graph becomes linear, making the history appear as if all changes were made sequentially on one branch.

Key differences

  1. History:

    • git merge preserves the full history of both branches, while git rebase creates a linear history.
  2. Use case:

    • Use git merge when you want to maintain the complete history of the project.
    • Use git rebase when you want to clean up the history, making it linear and easier to follow.
  3. Collaboration:

    • git merge is safer in collaborative environments since it preserves all commit history.
    • git rebase can be problematic in collaborative environments because it rewrites commit history, which can confuse collaborators.
  4. Conflicts:

    • Both commands can result in conflicts that need to be resolved manually.
    • The process of resolving conflicts is similar in both cases, but git rebase might involve resolving conflicts multiple times if replaying many commits.

How to cherry-pick commits: git cherry-pick

The git cherry-pick command is used to apply the changes introduced by an existing commit onto the current branch. This allows you to selectively incorporate specific changes without merging entire branches.

  • Selective changes: git cherry-pick is useful for applying specific changes without merging entire branches.
  • Potential conflicts: Be aware that cherry-picking commits can lead to conflicts, especially if the changes depend on other commits that are not present in the current branch.

What git cherry-pick does

When you run git cherry-pick, Git:

  • Applies the changes from the specified commit to the current branch.
  • Creates a new commit on the current branch with those changes.

When to use git cherry-pick

  • Hotfixes: Apply critical bug fixes from one branch to another without merging the entire branch.
  • Selective feature inclusion: Incorporate specific features or changes from a feature branch into another branch.

How to use git cherry-pick

To cherry-pick a commit, you use the git cherry-pick command followed by the commit hash of the commit you want to apply. Here's the basic syntax:

  • How to cherry-pick a specific commit:
git cherry-pick commit-hash

Cherry-pick example

  1. Identify the commit hash of the commit you want to cherry-pick by using the git log command:
git log
  1. Switch to the branch where you want to apply the commit:
git checkout target-branch
  1. Cherry-pick the specified commit:
git cherry-pick 1a2b3c4d5e6f7g8h9i0jklmnopqrstuvwx
  1. If there are no conflicts, Git will apply the changes and create a new commit.
  2. If there are conflicts, Git will pause and prompt you to resolve them. After resolving conflicts, continue the cherry-pick:
git add resolved-file
git cherry-pick --continue
  1. If you want to abort the cherry-pick and return to the original state, use:
git cherry-pick --abort

How to manage cherry-pick conflicts

Conflicts can occur during a cherry-pick, just like during a merge or rebase. Here's how to handle them:

  1. Git will pause and mark the conflicted areas in the files.
  2. Open each conflicted file and manually resolve the conflicts.
  3. Stage the resolved files using git add.
  4. Continue the cherry-pick with git cherry-pick --continue.
  5. If you encounter more conflicts, repeat the process until the cherry-pick is complete.

How to use GitHub

In this section, we will start our journey with GitHub.

Registering on GitHub

To start off, navigate to github.com and click Sign up. Registration is free and you can use GitHub to host both public and private repositories without paying anything.

You'll need to enter your email and a username that will be publicly visible. Then feel free to set up your personal profile (manage your avatar, bio, and so on).

How to create a repository on GitHub

Creating a new repository on GitHub is a very simple process. First, log into your GitHub account and then press the "plus" icon in the top menu. Choose "New repository":

Creating a new repository on GitHub

Then simply provide the name of your repository and choose the access level (public or private):

Providing repository details on GitHub

Once you are ready, hit Create repository.

You'll be provided with some quick start instructions. You can create a new file or upload an existing one using the graphical editor or connect your local repository to the repository created on GitHub by following the listed commands. In fact, most of the provided commands are already known to you, and we'll cover the unknown ones in the next section:

Quick start instructions for a new repository on GitHub

How to delete a repository in GitHub

If you'd like to delete your GitHub repository, first open it in your browser (the URL will be similar to https://github.com/username/reponame).

Then click Settings in the top menu:

GitHub repository settings button

You'll be navigated to the repository general settings. Scroll to the bottom and click the Delete this repository button:

Delete repository button in GitHub settings

You'll be prompted to confirm this action, so make sure you fully understand the consequences. Specifically, you'll permanently remove the remote repository itself with all its commit history, as well as any associated wiki, issues, comments, packages, secret keys, workflow runs, and remove all collaborator associations.

How to download files from GitHub

If you just need to download files from a GitHub repository without performing any additional setup, it's possible as well. Simply open the repository you're interested in and click "Code > Download ZIP":

Downloading a ZIP file from GitHub

This will download all contents of the repo to your local PC.

Alternatively, you can open a specific file on GitHub and click the Raw button:

Opening a file in raw format on GitHub

This will open the raw file contents in your browser, and you can simply copy-paste it.

Connecting GitHub with local Git

Now that you've set up your GitHub account and created a repository, it's time to connect your local Git with GitHub. This allows you to push changes from your local machine to the remote repository on GitHub.

To securely push changes to your GitHub repositories, you can use the Git Credential Manager (GCM), which simplifies the authentication process.

Installing Git Credential Manager (GCM):

  1. Windows: Git Credential Manager comes bundled with Git for Windows, so you don't need to install it separately.

  2. macOS: You can install GCM using Homebrew:

brew install git-credential-manager-core
  1. Linux: Follow the installation instructions from the GCM documentation .

How to configure Git to use the credential manager

After installing GCM, configure Git to use it by running the following command:

git config --global credential.helper manager-core

Authenticating with GitHub

When you first push or pull from a GitHub repository (these commandы will be covered in the next section), Git will prompt you to log in via a web browser. Here's how it works:

  1. Push or pull changes:
git push origin main
  1. Authenticate via web browser: Git will open a web page where you can log in to your GitHub account and authorize Git to access your repositories.

  2. Credential storage: Once authorized, GCM will securely store your credentials, so you won't need to log in again for future operations.

Once you've authenticated, you can push changes to your GitHub repository without any problems.

Git commands and approaches for remote repositories

How to manage remote repositories: git remote

The git remote command is used to manage the set of remote repositories. These are versions of your project that are hosted on the internet or another network. Adding a remote repository allows you to collaborate with others by pushing and pulling changes.

What git remote add does

When you run git remote add, Git performs the following actions:

  • Registers the specified URL under the given name in your local repository.
  • Allows you to use this name to interact with the remote repository using commands like git push, git pull, and git fetch.

How to use git remote

Here are some common usages of the git remote command:

  • How to add a remote repository:
git remote add <name> <url>
  • How to list remote repositories:
git remote -v
  • How to remove a remote repository:
git remote remove <name>
  • How to rename a remote repository:
git remote rename <old-name> <new-name>

Example: How to add remote origin

To add a remote repository, you use the git remote add command followed by a name for the remote and the URL of the remote repository. Here's the basic syntax:

  • Add a remote repository:
git remote add origin https://github.com/username/repository.git

Verify that the remote repository has been added:

git remote -v

This will display the remote repositories and their URLs:

origin https://github.com/username/repository.git (fetch)
origin https://github.com/username/repository.git (push)

Example: How to remove a remote origin

If you need to remove a remote repository, you can use the git remote remove command followed by the name of the remote. For example:

  • Remove a remote repository:
git remote remove origin

This command unregisters the remote repository from your local Git configuration, which can be useful if the remote repository is no longer needed or has been moved.

How to clone a Git repository: git clone

The git clone command is used to create a copy of an existing Git repository. It downloads the repository from a remote source and sets up the necessary files and directories on your local machine.

What git clone does

When you run git clone, Git performs the following actions:

  • Creates a new directory with the same name as the repository.
  • Initializes a new Git repository in that directory.
  • Downloads all the files and the entire commit history from the remote repository.
  • Sets up the remote repository as the origin, linking your local repository to the remote one.

How to use git clone

To clone a repository, you use the git clone command followed by the URL of the repository. Here's the basic syntax:

  • How to clone a repository:
git clone <repository-url>

For example, you can clone a GitHub repository locally in the following way:

git clone https://github.com/username/repository.git

A new directory named repository will be created, and you can navigate into it:

cd repository

You now have a local copy of the repository with the full commit history and all files.

Common options

The git clone command has several options to customize the cloning process:

  • How to clone a repository into a specific directory:
git clone <repository-url> <directory>

Example:

git clone https://github.com/username/repository.git my-directory
  • How to clone a specific branch:
git clone -b <branch-name> <repository-url>

Example:

git clone -b develop https://github.com/username/repository.git
  • How to clone with a depth of history:
git clone --depth <depth> <repository-url>

Example (clones only the last 5 commits):

git clone --depth 5 https://github.com/username/repository.git

How to fetch data from a remote repository: git fetch

The git fetch command is used to download commits, files, and references from a remote repository into your local repository. Unlike git pull, git fetch only retrieves the changes and does not merge them into your current branch.

What git fetch does

When you run git fetch, Git performs the following actions:

  • Downloads the latest changes from the specified remote repository.
  • Updates your local repository with the fetched changes, storing them in remote-tracking branches.
  • Does not modify your working directory or current branch.

How to use git fetch

To fetch changes from a remote repository, you use the git fetch command followed by the name of the remote. Here's the basic syntax:

  • How to fetch changes from a remote repository:
git fetch <remote>

For example, to fetch the changes from the remote repository:

git fetch origin

Git will download the latest changes from the origin remote repository and store them in origin/main (or other appropriate remote-tracking branches).

If you want to incorporate the fetched changes into your current branch, you can manually merge or rebase:

git merge origin/main
or
git rebase origin/main

Common options

The git fetch command has several options to customize the fetching process:

  • How to fetch all remotes:
git fetch --all

This fetches changes from all configured remotes.

  • How to prune deleted branches:
git fetch --prune

This removes any remote-tracking references that no longer exist on the remote.

  • How to fetch tags:
git fetch --tags

This fetches all tags from the remote repository.

How to pull from a remote repository: git pull

The git pull command is used to fetch and merge changes from a remote repository into your current branch. It combines the functionality of git fetch and git merge, updating your local repository with the latest changes from the remote.

What git pull does

When you run git pull, Git performs the following actions:

  • Fetches the latest changes from the specified remote repository and branch.
  • Merges the fetched changes into your current branch.

How to use git pull

To pull changes from a remote repository, you use the git pull command followed by the name of the remote and the branch you want to pull from. Here's the basic syntax:

  • How to pull changes from a remote repository:
git pull <remote> <branch>

For example, to checkout to the main branch:

git checkout main

Then, pull changes from the remote repository:

git pull origin main

Git will fetch the latest changes from the main branch of the origin remote repository and merge them into your current main branch.

How to resolve pull conflicts

Conflicts can occur during a pull if changes in the remote repository conflict with your local changes. Here's how to handle them:

  1. Git will pause and list the files with conflicts.
  2. Open each conflicted file and manually resolve the conflicts.
  3. Stage the resolved files using git add:
git add resolved-file
  1. Complete the merge by committing the changes:
git commit

Common options

The git pull command has several options to customize the pulling process:

  • How to rebase instead of merge:
git pull --rebase <remote> <branch>

This fetches the changes and rebases your current branch on top of the fetched branch.

  • How to only fetch changes without merging:
git fetch <remote> <branch>

This allows you to review the changes before merging them manually.

git fetch vs git pull

While both git fetch and git pull are used to retrieve updates from a remote repository, they serve different purposes and work in different ways:

  • git fetch:

    • Downloads changes from the remote repository.
    • Updates remote-tracking branches with the latest changes.
    • Does not modify your working directory or current branch.
    • Allows you to review changes before incorporating them.
  • git pull:

    • Combines git fetch and git merge in one step.
    • Downloads changes from the remote repository and immediately merges them into your current branch.
    • Modifies your working directory and current branch with the latest changes.
    • Useful for quickly updating your branch with remote changes, but can lead to merge conflicts that need to be resolved immediately.

In summary, use git fetch when you want to review changes before merging them, and use git pull when you want to quickly integrate remote changes into your current branch.

How to push commits: git push

The git push command is used to upload your local repository changes to a remote repository. This command updates the remote repository with your commits, allowing others to access and collaborate on the project.

What git push does

When you run git push, Git performs the following actions:

  • Uploads your local commits to the specified branch of the remote repository.
  • Updates the remote branch to match your local branch.

How to use git push

To push changes to a remote repository, you use the git push command followed by the name of the remote and the branch you want to push to. Here's the basic syntax:

  • How to push changes to a remote repository:
git push <remote> <branch>

For example, commit your changes in the local repository:

git commit -m "Your commit message"

Push the changes to the remote repository:

git push origin main

Git will upload your local commits to the main branch of the origin remote repository.

Common options

The git push command has several options to customize the pushing process:

  • How to set upstream for the branch:
git push -u <remote> <branch>

This sets the remote branch as the default upstream branch for future pushes.

  • How to force push (use with caution):
git push --force

This forcefully updates the remote branch to match your local branch, potentially overwriting changes.

How to resolve push conflicts

Conflicts can occur during a push if the remote branch has changes that your local branch does not. Here's how to handle them:

  1. Git will reject the push and display an error message.
  2. Pull the latest changes from the remote repository:
git pull origin main
  1. Resolve any conflicts that arise.
  2. Commit the resolved changes:
git commit -m "Resolved conflicts"
  1. Push the changes again:
git push origin main

How to create tags: git tag

The git tag command is used to create, list, delete, and verify tags in Git. Tags mark specific points in your commit history as important, such as releases or significant milestones.

What git tag does

When you create a tag, Git assigns the specified tag name to a particular commit. Tags can be lightweight or annotated:

  • Lightweight tags: These are simply pointers to a commit. They don't store any additional information.
  • Annotated tags: These store extra metadata such as the tagger's name, email, date, and a message. Annotated tags are stored as full objects in the Git database.

How to use git tag

Here are some common usages of the git tag command:

  • How to create a lightweight tag:
git tag <tagname>
  • How to create an annotated tag:
git tag -a <tagname> -m "Tag message"
  • How to list all tags:
git tag
  • How to show details of a specific tag:
git show <tagname>
  • How to delete a tag:
git tag -d <tagname>

Pushing tags to a remote

Tags are not automatically pushed to remote repositories. You need to push them explicitly:

  • How to push a single tag:
git push origin <tagname>
  • How to push all tags:
git push origin --tags

How to checkout tags

You can also check out a tag to view the state of your project at the point where the tag was created. However, this puts you in a "detached HEAD" state, meaning you are not on any branch:

git checkout <tagname>

How to fork a repository

What is forking?

Forking is a process provided by platforms like GitHub that allows you to create a personal copy of someone else's repository under your own GitHub account. This is useful for making changes to a project without affecting the original repository. It's commonly used for contributing to open source projects.

How to fork a repository on GitHub

  1. Navigate to the repository you want to fork.

  2. Click the "Fork" button:

Fork button on GitHub

  1. If you belong to multiple organizations, you might need to choose where to fork the repository:

Choose fork target on GitHub

After forking, you will have your own copy of the repository on GitHub, which you can modify independently of the original repository.

Using forks with Git

Once you have forked a repository on GitHub, you can clone it to your local machine and work with it using standard Git commands:

  1. Clone the forked repository:
git clone https://github.com/your-username/forked-repository.git
  1. Add the original repository as a remote:
git remote add upstream https://github.com/original-username/original-repository.git
  1. Fetch changes from the original repository (in case the original repository has been updated since the time you've created your fork):
git fetch upstream
  1. Merge changes from the original repository into your fork:
git merge upstream/main

How to contribute on GitHub with pull requests

By using the fork-and-pull model, you can contribute to projects by making changes in your forked repository and then creating pull requests (PRs) to propose changes to the original repository.

How to create a pull request

  1. Make changes in your forked repository: Use Git commands like git add, git commit, and git push to make and push changes to your forked repository.

  2. Create a pull request:

  • Navigate to the original (not forked!) repository on GitHub.
  • Click on the "Pull requests" tab:

Pull requests tab on GitHub

  • Click the "New pull request" button:

New pull request button on GitHub

  • Select the branch of your forked repository that contains the changes. You might also need to click "compare across forks":

Comparing branches for pull request on GitHub

  • In the image above, the repository to the left (base) is the repo that you are sending your pull request to. The repository to the right (head) is your forked repository. Below, you'll see the commits that you'll be including in the pull request. Here you can compare your changes with the original repository's branch (e.g., main).
  1. Submit the pull request:
  • Click the "Create pull request" button.
  • Write a descriptive title and description for your pull request:

Creating a pull request on GitHub

Your pull request will now be reviewed by the maintainers of the original repository. They may provide feedback or request changes. Once the pull request is approved and merged, your contributions will be incorporated into the original repository.

How pull requests relate to git push and forks

  • Fork: You create a personal copy of the original repository.
  • git clone: You clone your forked repository to your local machine.
  • git add/commit/push: You make changes locally and push them to your forked repository on GitHub.
  • Pull request: You propose changes from your forked repository to the original repository.

Frequently Asked Questions

What is Git?

Git is a distributed version control system created by Linus Torvalds in 2005. It helps developers track changes in their code, collaborate on projects, and manage their codebase efficiently.

What does Git mean?

The term "Git" is a British slang meaning "unpleasant person," humorously chosen by Linus Torvalds because he described himself as such.

How to use Git?

You use Git by running commands in your terminal. Some basic commands include git init to create a repository, git add to stage changes, git commit to save changes, git push to upload changes to a remote repository, and git pull to fetch and merge changes from a remote repository.

What is Git Bash?

Git Bash is a command-line interface for Windows that provides an emulation layer for a Git command-line experience. It offers a Unix-like terminal environment that allows users to use Git commands as if they were on a Unix-based system, such as Linux or macOS.

Git Bash includes the following features:

  • Git Command-Line Tools: The full set of Git command-line tools, allowing you to perform version control tasks such as committing, branching, merging, and more.
  • Bash Shell: A Bash shell, which is a Unix shell and command language. This enables users to use Unix-like commands and scripts on Windows.
  • File System and Path Translation: Translates between Unix-style file paths and Windows paths, making it easier to work across different operating systems.

To install Git Bash, you can download the Git for Windows package from the official Git website . During installation, you can choose to include Git Bash as part of the Git for Windows setup.

How to delete .git folder?

To delete the .git folder and effectively uninitialize a Git repository, run:

rm -rf .git

Use this command with caution as it will remove all version history.

You can also remove this directory with a graphical interface within your OS. However, be aware that this folder might be hidden, so you'll need to display hidden folders on your OS.

What are Git hooks?

Git hooks are scripts that run automatically on specific Git events, like committing or merging. They are used to enforce policies, automate tasks, and integrate with other tools.

What are Git submodules?

Git submodules are a way to include one Git repository as a subdirectory of another Git repository. This allows you to keep separate repositories for different components of a project, while still being able to manage them within a single parent repository. Submodules are useful for including external dependencies or shared libraries.

If you need to clone a Git repository including its submodules, run:

git clone --recursive 

What is Git fast forward?

A fast-forward in Git occurs when a branch being merged has not diverged from the branch it is being merged into. In this scenario, Git can simply move the branch pointer forward to the latest commit without creating a new merge commit.

When you perform a fast-forward merge, the commit history remains linear, and no additional merge commit is created. This is the default behavior when you merge a branch that is directly ahead of the current branch without any conflicting changes.

For example, if the main branch has commits A and B, and a feature branch is created from B and has new commits C and D, merging the feature branch back into main can be done via fast-forward, moving the main branch pointer to commit D:

Before merge:
main: A -- B
feature: A -- B -- C -- D

After fast-forward merge:
main: A -- B -- C -- D

Fast-forward merges are clean and simple, maintaining a linear project history. However, if you want to preserve the feature branch's context or need to merge diverged branches, a non-fast-forward merge (which creates a merge commit) might be preferred.

What is Git LFS?

Git LFS (Large File Storage) is an extension for Git that allows you to manage large files and binary files by storing them outside your repository while keeping pointers inside the repository.

What is GitHub and what is it used for?

GitHub is a web-based platform that hosts Git repositories. It is used for version control, collaboration, and project management. It provides additional features like pull requests, issue tracking, and GitHub Actions for CI/CD.

Who owns GitHub?

GitHub is owned by Microsoft, which acquired it in 2018.

What are GitHub Actions?

GitHub Actions is a CI/CD (Continuous Integration/Continuous Deployment) service provided by GitHub. It allows you to automate workflows for building, testing, and deploying your code directly from your GitHub repository.

What is GitHub Pages?

GitHub Pages is a free service from GitHub that lets you create websites directly from your GitHub repositories. It's very handy for hosting project documentation, personal blogs, or any static websites. You just push your code to a specific branch, and GitHub does the rest, making your site live with a URL like yourusername.github.io/your-repo-name. No need for a separate web host or complex setup (though it's possible to attach a custom domain later).

How does GitHub make money?

GitHub makes money through its subscription plans, which offer additional features for private repositories, enterprise-level services, and advanced collaboration tools. They also provide GitHub Marketplace, GitHub Sponsors, and GitHub Actions minutes for additional revenue.

What is IPTV GitHub?

IPTV GitHub refers to repositories on GitHub that host lists of IPTV (Internet Protocol Television) channels. These lists can be used with IPTV applications to stream TV channels over the internet.

Conclusion

We've covered a lot of ground in this guide, from the basics of Git to advanced features and how to make the most of GitHub. By now, you should have a solid understanding of how to use Git to track changes, manage branches, and collaborate with others. GitHub's powerful tools make it easier to work on projects, whether you're part of a team or contributing to open-source projects.

Remember, practice makes perfect. The more you use Git and GitHub, the more comfortable you'll become with these essential tools. Don't hesitate to revisit this guide whenever you need a refresher or encounter something new.

Happy coding, and enjoy your journey with Git and GitHub!

image description
Ilya Krukowski

Ilya is an IT tutor and author, web developer, and ex-Microsoft/Cisco specialist. His primary programming languages are Ruby, JavaScript, Python, and Elixir. He enjoys coding, teaching people and learning new things. In his free time he writes educational posts, participates in OpenSource projects, tweets, goes in for sports and plays music.