DevOps

A Beginner’s Guide to Git and Github 

Introduction

Are you just starting with Git and GitHub? Do you feel attracted to this tool but fear being confused about the overall process? This article will crystal clear your basic concepts about this tool and help you create a repository at the same time. Fundamental steps like adding, making commits, creating push requests, and many more are part of this article. So, overall, this is a great article to sharpen your knowledge about the tool Git and its library, GitHub. Now, we urge you to dive deep into this Git world with our article. 

Understanding Git and GitHub

Understanding Git and GitHub

Git is like a personal assistant for coders. This assistant is a pro at noting down every change to help the coder retain effective changes. You may ask what the need is to minutely observe the changes in the code. Well, the creator of the codebase or the team associated with it might want to track the progress just like you do it in Google Docs. Also, there might be a requirement to troubleshoot an error by observing the recent changes. Sometimes, the creator may want to shift to the previous era with the old codes; at this point, Git can be a great help to him/her.

Now that you have a basic idea of what Git can do and why a coder might need this tool, let’s discuss GitHub. So, where do you think such a large chunk of information gathered by Git is stored? It is quite obvious that all this information needs a safe spot. That’s where GitHub comes into the picture. Git observes the changes and takes snapshots, while GitHub is the platform where these snapshots are safely parked. With basic information on both of these terms, we would like to push you toward the next section, which focuses on the usage of Git and GitHub.

Steps to use Git & Github

This section will talk from zero to a hundred about getting started with the Git tool and GitHub login

Step 1 – Install Git

This is the most basic step of starting with this tool. Here, you will have to install Git on your device as per your operating system. Follow different approaches for different OS; take a look below.

a. Windows

Download the latest Git version from the official Git website. Complete the whole installation process through the given prompts. Once the installation of Gitis is done, you need to configure it by setting up your email and password. To enter your user name, use the command “git config –global user.name “Your Name” in the terminal of your device. For email, enter the command “git config –global user.email” in the terminal.

b. Linux

The installation process of Git on Linux is quite simple due to the presence of a package manager like “apt”. All you have to do is enter the command “sudo apt update” in the terminal to update the package manager. Once it is done, you just have to enter the command “sudo apt install git” and the package manager will take care of the entire process. 

c. Mac

The most suitable package manager for Mac is Homebrew, which is why you need to install it through the below command. 

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Now, it is time to install Git via Homebrew, for which the following command will help you: 

brew install git

Step 2 – Start a GitHub account

Creating your own GitHub account is very similar to creating an email account. You have to go to the official website, look for the signup option, and simply start the registration process. Once you have correctly entered the captcha and all the details, you will have your GitHub login within no time.

Step 3 – Create a local repository

A local repository is like a personal folder of the Git tool to store all the information. As a user, you need to create this folder through the command “cd path/to/your/directory”, which will take you to the location where you want to place your repository folder. When the location of the directory suits your preference, simply enter the command “git init” in the terminal to initiate the creation.

Step 4 – File addition

The developmental stage of the project includes new files, images, documents, and much more. To complete the tracking process, you will need a new file, which can be easily added to the repository through your terminal window. First of all, create a file by using the “touch” command. For example, to create a file named “example.txt”, you would type:

touch example.txt

Once you have created the file, use the command “git add” to complete the staging process. Here, the staging process refers to the part where the file is prepared for the snapshot to be taken by the Git tool. Now, all you have to do is to approve the snapshot by using the committing command “git commit -m “Add new file.”

Step 5 – Start a new repository on GitHub

This is the point when you will have the requirements for the GitHub desktop. It makes it easier for you to work with your team, as every change can be tracked by any member of the team through Git and GitHub. Now, you will have to create a new repository on GitHub by entering your login details on the official website. Once you have logged in, simply look for the “+” sign in the upper right corner and click on the new repository option. Fill out all the details and finish the process.

Step 6 – Direct a branch towards GitHub

The most important step is to let others know about the changes. To do this, you will have to direct the branch containing the new repository to the GitHub desktop. So, it is time to connect your local repository to your GitHub repository through the command “git remote add origin <repository_URL>”. Finally, enter the below command to push the branch.

git push -u origin

Step 7 – Start and merge a pull request 

Before you can merge changes from one branch to another, you need to have a proper pull request. To do so, open the GitHub repository and click on the “pull request” option. Inside that option, go to the “new pull request.” Now, simply select both the branches you want to merge and click on the “Create pull request” option. At the end, you can merge the pull request through the “merge pull request” option. 

Conclusion

The world of Git and GitHub might seem daunting at first, but it’s a powerful journey for managing and collaborating on code. Git acts like a meticulous note-taker, recording every change made, allowing for meticulous observation of code progress, troubleshooting, and even reverting to previous versions. GitHub serves as the haven for these recorded changes, storing snapshots created by Git.

This beginner’s guide decodes the process, starting from installing Git, creating a local repository, adding files, making commits, branching for modifications, setting up a GitHub account, creating a repository, linking local and GitHub repositories, initiating pull requests, and syncing changes between devices. Remember, while these steps might appear complex initially, with practice, Git and GitHub will become invaluable tools in your coding journey. 

Hostbillo Team

The blogs are written by a team of in-house technical content experts. They handle everything from research to writing and publishing.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *