Git & GitHub for 10 years old.

A Beginner’s Guide to Git and GitHub for Complete Newbies.

Kɪʟʟᴜᴀ
12 min readJan 6, 2023

Welcome to the world of Git and GitHub! If you’re new to the world of software development or just starting out with coding in general, you’ve probably heard these terms mentioned frequently and may be wondering what they’re all about. Don’t worry, this article will help clarify any doubts you may have and make GitHub a place where you Fork.

It’s important to note that Git and GitHub are not the same thing. Git is an open-source, version control tool developed in 2005 by Linux developers, while GitHub is a company founded in 2008 that offers tools that integrate with git. While you don’t need to use GitHub to use git, you can’t use GitHub without git. There are many other options for hosting and collaborating on code, such as GitLab, BitBucket, and self-hosted solutions like gogs and gittea. These are all referred to as “remotes” in the world of git, and while they can be useful for sharing your code with others, they are not required to use git.

Despite the common portrayal by popular media, the life of a software developer does not consist of solitary confinement in a dimly lit room, hunched over a computer with only the monitor’s glow for company. On the contrary, being a software developer is a social and collaborative endeavor, sometimes to the point of irritation. It is for this very reason that tools such as git and GitHub exist, to aid in the process of working with others toward a common goal.

Git is a version-control tool that simplifies collaboration with your team members, once you’ve conquered the initial learning curve. It can be a bit intimidating at first, but that’s where I come in! With a little guidance and some practice, you’ll be a pro at using git in no time.

What is Git?

Contrary to popular belief, git is not just a colloquialism used to shoo pests off porches in the southern United States. Rather, it is a powerful version-control software tool developed by Linus Torvalds, the creator of Linux. However, you don’t need to be running Linux to use git — it is also available for Windows and Mac operating systems.

Git allows you and your team to keep track of every revision made during the development of your software project. It allows you to share a single repository of code, which can be worked on independently and then merged back together. Git also enables you to work on your project remotely, as it is saved both locally on each machine and on a remote platform such as Github.

Git is a powerful tool that makes it easy to track the changes you and your team make to your codebase over time. It allows you to revert to previous versions, create separate branches to work on specific features without impacting the main code and ensure data integrity through its distributed nature. With robust encryption and cross-platform compatibility, git enables you to work on your project from anywhere, using asynchronous, non-linear workflows that allow for flexible collaboration.

If you’re not using git, you’re missing out on a valuable tool that can greatly enhance your software development process.

Git Terminology for Beginners:

Starting out with git can be intimidating, as the commands and concepts may be unfamiliar if you’ve never used a version control system before. However, with a little practice, you’ll pick them up quickly. Here’s a list of some key terms you should know:

  • Repository (repo): A collection of files and folders that git is used to track. The repository includes the entire history of changes made to the project by your team.
  • GitHub: A popular platform for hosting and collaborating on git repositories. It allows you to set access permissions, track and submit bugs, accept feature requests, and use a graphical interface rather than the command line. Repositories on Github are public by default, but paid accounts can have private ones.
  • Commit: A way of saving your work in git. When you commit to a repository, it’s like putting the current state of your files into a time capsule. Commits exist only on your local machine until they are pushed to a remote repository.
  • Push: The process of synchronizing your commits to a remote repository, usually on Github. You can push multiple commits at once, and work offline by committing changes and pushing them to GitHub when you have an internet connection.
  • Branch: A separate instance of the code that branches off from the main codebase. You might create a branch to work on a specific feature or experiment without impacting the main code. Branches allow you to preserve the integrity of the software and revert to a previous version if necessary, as well as work on your task without disturbing others.
  • Merge: The process of integrating two branches together. When a branch is ready to be incorporated into the primary codebase, it is merged into the master branch. This adds any new or updated code to the official codebase and makes it available to anyone who branches off from that point.
  • Clone: A process that creates an exact copy of an online repository on your local machine. You might clone a repository to start working on a project with a new team, switch to a different computer, or recover from a corrupted repository.
  • Fork: A process that creates a new repository based on an existing one, with your own name as the owner. This is often used in open-source software to take an existing codebase in a new direction or to experiment with someone else’s code in a separate repository.
  • Pull request: A request to merge the changes you’ve made (either on a branch or a fork) into the master branch of a repository. If the pull request is accepted, your changes will be officially added to the software and will be credited to you on GitHub. If it is denied, the person rejecting the request can provide feedback on why and what you can do to improve the request.
  • Merge conflict: A situation that occurs when two or more branches have made conflicting changes to the same lines of code, and git is unable to automatically merge them. You will need to resolve the conflict by deciding which changes to keep or discard.
  • Remote: A remote repository that is stored on a platform other than your local machine. This could be a service like GitHub, GitLab, or BitBucket, or a self-hosted solution like gogs or gitea. Remotes allow you to share your code with others and collaborate on projects.

Getting Started with Git and Required Commands:

Now that you have a good understanding of what git is, it’s time to start using it! This tutorial will focus on using the command line to interact with git, although there are also graphical git clients and web interfaces available. The command line may seem intimidating at first, but it’s a valuable skill to have and will quickly become your go-to tool for working with git. Let’s dive in!

Installing Git:

Git is likely not installed on your computer by default, so you’ll need to install it before you can use it. Installing git is quick and easy, no matter what operating system you’re using.

On Linux, open the terminal and type sudo apt-get install git-all (if you're using Ubuntu. If not, check the list of Linux package installation commands for your specific distribution).

On Windows, simply download the installer and run it.

On Mac, open the terminal and type git. If git is not installed, you will see a message indicating that it is not found. In that case, you can install git by running brew install git (assuming you have Homebrew installed).

See? Super easy!

Once git is installed, you’re ready to start using it!

cheat:

As you embark on your journey to learn Git and GitHub, it’s important to note that you don’t need any prior experience with the terminal to get started. In fact, there’s an easy way to use Git and GitHub without ever having to touch the command line. Simply install GitHub Desktop on your computer, sign in to your GitHub account, and you’re ready to go! No need to worry about complicated terminal commands — just start using Git and GitHub to your heart’s content.

GitHub Desktop is a great tool for those who want to use Git and GitHub without having to use the terminal or command line. Let’s go over how to install GitHub Desktop and use it to manage your Git repositories.

First, let’s go over how to install GitHub Desktop. Head over to the GitHub Desktop website (https://desktop.github.com/) and click the “Download” button. Once the download is complete, open the installer file and follow the prompts to install GitHub Desktop on your computer.

Once GitHub Desktop is installed, you’ll need to sign in to your GitHub account. Click the “Sign In” button in the top right corner of the GitHub Desktop window and enter your login credentials.

Now that you’re signed in, let’s take a look at the GitHub Desktop interface. On the left side of the window, you’ll see a list of your Git repositories. To create a new repository, click the “Create a new repository” button in the top left corner of the window. Give your repository a name and click “Create repository.”

To clone an existing repository, click the “Clone a repository” button in the top left corner of the window. You’ll be prompted to enter the URL of the repository you want to clone. Once you’ve entered the URL, click “Clone.”

Once you have a repository set up, you can start working with your files. To make changes to a file, simply double-click on the file in the repository list. This will open the file in your default text editor. Make your changes, save the file, and then return to GitHub Desktop.

To commit your changes to the repository, enter a commit message in the “Summary” field at the bottom of the window. This message should briefly describe the changes you made to the file. Then, click the “Commit to master” button. This will save your changes to the repository.

To push your changes to the remote repository on GitHub, click the “Push origin” button in the top right corner of the window. This will upload your changes to the remote repository, making them available to other users.

GitHub Desktop is a great tool for those who want to use Git and GitHub without having to use the terminal or command line. With a little practice, you’ll be managing your Git repositories like a pro!

Although it’s possible to use Git and GitHub without the terminal, as true professionals, we will strive to master all aspects of these powerful tools. That’s why, as we progress, we’ll also delve into the world of the terminal and command line. There’s no time to waste — let’s get started on our journey to becoming Git and GitHub pros.

Using Git:

After installing git, you’ll need to create a new repository. A repository is essentially a folder that contains all of the files and directories associated with your project. To create a new repository, open a terminal or command prompt and navigate to the directory where you want to store your repository. Then, type the following command:

git init

This will create a new Git repository in the current directory.

Now that you have a repository set up, you can start adding files to it. To add a file to your repository, type the following command:

git add [filename]

Replace “[filename]” with the name of the file you want to add. For example, if you want to add a file called “main.py”, you would type:

git add main.py

To commit your changes to the repository, use the following command:

git commit -m "[commit message]"

Replace “[commit message]” with a brief message describing the changes you made to the file. This message should be written in present tense and should be concise. For example, “Add main.py” or “Fix bug in login system.”

Once you’ve made your changes and committed them to the repository, you can push them to a remote repository (e.g. on GitHub) using the following command:

git push

This will upload your changes to the remote repository, making them available to other users.

To view the status of your repository, use the following command:

git status

This will show you a list of the files that have been modified or added to the repository since the last commit. It will also show you any untracked files (files that are not being tracked by Git).

To view the commit history of your repository, use the following command:

git log

This will show you a list of all the commits that have been made to the repository, along with the commit message and the date of the commit.

To revert a file to a previous version, you can use the “git revert” command. For example, to revert a file called “main.py” to the version from the previous commit, you would use the following command:

git revert HEAD main.py

This will undo the changes made to “main.py” in the last commit, and create a new commit with the changes.

Git also allows you to create branches, which are essentially separate versions of your code that you can work on simultaneously. To create a new branch, use the following command:

git branch [branch name]

Replace “[branch name]” with the name of your new branch. For example, “git branch feature-x” will create a new branch called “feature-x”.

To switch to a different branch, use the following command:

git checkout [branch name]

This will switch you to the specified branch, allowing you to work on the code in that branch.

Git also has a powerful feature called “merging,” which allows you to combine the changes from one branch into another branch. This is often used when you have been working on a separate branch and want to merge your changes back into the main branch (usually called “master”).

To merge one branch into another, first switch to the branch you want to merge into. For example, if you want to merge the “feature-x” branch into the “master” branch, you would first switch to the “master” branch using the following command:

git checkout master

Then, use the “git merge” command to merge the other branch into the current branch. For example:

git merge feature-x

This will combine the changes from the “feature-x” branch into the “master” branch.

It’s important to note that Git will try to automatically merge the branches if there are no conflicts. However, if there are conflicts (e.g. if you made changes to the same lines of code in both branches), Git will not be able to automatically merge the branches. In this case, you will need to resolve the conflicts manually by editing the affected files and committing the changes.

Git also has a feature called “rebasing,” which allows you to apply the changes from one branch onto another branch. This is similar to merging, but the resulting commit history is different. Instead of creating a new commit for the merge, rebasing replays the commits from the other branch onto the current branch.

To rebase one branch onto another, use the following command:

git rebase [branch name]

For example, to rebase the “feature-x” branch onto the “master” branch, you would use the following command:

git rebase feature-x

Like merging, rebasing can also result in conflicts if there are changes to the same lines of code in both branches. In this case, you will need to resolve the conflicts manually before the rebase can be completed.

In addition to using Git from the command line, you can also use a graphical user interface (GUI) to interact with Git. There are many different Git GUI tools available, ranging from simple desktop applications to full-featured integrated development environments (IDEs).

One popular Git GUI is GitKraken, which is available for Windows, Mac, and Linux. GitKraken provides a visual representation of your repository, allowing you to see the commit history, branches, and other details of your project. It also has features for merging and rebasing, as well as integration with popular code hosting platforms like GitHub and GitLab.

Another popular Git GUI is GitHub Desktop, which is developed by GitHub itself. GitHub Desktop is a simple desktop application that allows you to manage your Git repositories and collaborate with other users. It has a simple interface and is a good choice for those who are new to Git.

There are also many Git GUI options available as plugins for IDEs like Visual Studio and Eclipse. These plugins provide Git integration directly within the IDE, allowing you to work with Git without leaving the development environment.

Using a Git GUI can be a good choice for those who are new to Git or who prefer a more visual interface. However, it’s important to note that you will still need to learn the basic commands and concepts of Git in order to effectively use a GUI.

Git is a powerful and essential tool for developers. Whether you use the command line, a GUI, or a combination of both, learning how to use Git will greatly improve your productivity and collaboration when working on software projects. With a little practice and patience, you’ll be a Git pro in no time! And you’ll be able to use Git to manage your code projects with ease. Happy coding!

--

--

Kɪʟʟᴜᴀ

Iɴᴅᴇᴘᴇɴᴅᴇɴᴛ Sᴇᴄᴜʀɪᴛʏ Rᴇsᴇᴀʀᴄʜ Eɴɢɪɴᴇᴇʀ. I sʜᴀʀᴇ ᴍʏ ɪɴsɪɢʜᴛs ᴀs I ᴛʀᴀᴠᴇʀsᴇ ᴛʜᴇ ғɪᴇʟᴅ ᴏғ ʙʟᴏᴄᴋᴄʜᴀɪɴ sᴇᴄᴜʀɪᴛʏ, @0xHʀɪᴅᴀʏ ᴀᴄʀᴏss ᴀʟʟ ᴘʟᴀᴛғᴏʀᴍs.