Git and GitHub Simplified: A Beginner's Guide to Version Control

Git and GitHub Simplified: A Beginner's Guide to Version Control

Streamlining the Basics of Version Control and Collaboration for Novice Developers

Git is a modern and widely used distributed version control system in the world. The version control system allows us to monitor and work with our team members in the same workspace.

This tutorial doesn't cover every aspect of git and GitHub but will provide you with enough knowledge to be comfortable using git and GitHub.

If you're a beginner developer, you might think that these two terms mean the same thing – but they're different.

Prerequisites

In order to complete this tutorial, you'll need the following:

• A command line interface.

• A text editor of your choice (I will be using Ubuntu).

• A GitHub account.

What is Git?

Git is a version control system that allows you to keep track of your codes and makes changes to your files.

What is Version Control System?

A version control system is basically software that helps developers to work together and maintain a complete history of their work. You can think of it as a digital time machine that allows you to go back to previous versions of your code and make changes as needed.

What Does Git Do?

  1. Save Time - Each command takes only a few seconds to execute so we can save a lot of time compared to logging in to a GitHub account.

  2. Offline Working - Git supports offline working which is crucial especially when facing internet connectivity issues, it will not affect one's work.

  3. Undo Mistakes - You're able to undo any mistakes made during your coding session using the "git restore" command.

  4. Track the Changes - You can track your codes and make changes to them using the git commands.

  5. Used By Multiple People - When a team works on real-life projects, git helps ensure no code conflicts between the developers.

How To Configure Git

To configure git, you need to follow these steps:

  • Install git on your computer

You need to install git on your computer in order to use it. To verify if you have git on your system, you can run this command on the command line: git --version.

  • Set up your identity

After installation, open a command line or terminal and run the following commands:

git config --global user.name "Your Name"
git config --global user.email "youremail@domain.com"

NOTE: Replace "Your Name" with your own name and email.

  • Configure your text editor

Git uses a text editor to prompt you for commit messages and other input. paste this code to configure your text editor:

git config --global core.editor nano

NOTE: You can replace "nano" with the name of your preferred editor.

Creating A File

We use the touch command to create a file in git, you type touch followed by the name of the file.

touch filename

Cloning a repository

  • After creating the repository on your GitHub, click on 'code' and copy the HTTPS URL.

  • Type git clone on your code editor and paste the URL.
git clone https://github.com/Tra-G/anymovie.git

How to add files in git

After cloning the repository and working on the files, your work is not being tracked by Git. To track your work, you will make use of the git add command. There are two methods of adding files on git:

  • git add . - The dot that comes after "git" means all the files that exist in the repository. So when you use git add ., it will add all the files in that repository.

  • git add file - This is used to add specific file

git add filename
git add .

How to commit files in Git

Git commit is used to save changes made to a project and record them in the project repository. It is the next stage after git add. To commit files of a project:

git commit -m "the commit message goes here"

git commit tells Git that all the files staged are ready to be committed so it is time to take a snapshot. -m stands for message and -m "the commit message goes here" is the commit message.

How to push your project to GitHub

After committing your project changes, the next step is pushing your work to your GitHub. If you don't have a GitHub repository, don't worry. I will explain the process.

To push your work, type git push.

git push

git push command is used to upload the committed changes to a remote repository - GitHub where you will be able to see all the changes you have made so far.

Navigating your way on GitHub

To get started on Git, you need a GitHub account where you will upload all committed changes.

Creating a GitHub account

Creating a repository

After creating an account, to get started with working on a project:

  • Click on new and create a repository.

Deleting a repository

  • To delete a repository on GitHub, go to the specific repository you want to delete.

  • Click on settings and scroll down to the bottom of the page where you will see "Danger Zone".

  • Click on the last option at the bottom which says Delete this repository.

NOTE: It is not advisable to delete a repository unless it is necessary.

Collaborating with people on GitHub

There are times when you will be required to collaborate with people in building projects and knowing how to collaborate with people on GitHub will help you a long way even while working.

To collaborate with people on GitHub:

  • Go to the repository you intend to work on.

  • Click on settings and on the left side, click on Collaborators and you can start adding people you want to collaborate with.

Knowing how to make use of these commands will make your job as a software developer easier and increase your experience.

If you found this article helpful, like and follow for more helpful content on web development.