Introduction to GitHub
Git is an essential part of programming, especially if you are working as a team, and is one of the most widespread collaborative tools. Every developer needs a version control system for getting his work aligned in chronological order. Git and Github certification are steeply rising and have now become a must-have skill from a preferred skill for numerous job roles today.
GitHub is densely used for modern version control systems and tracking down any updates made in computer files. The term version control system refers to a system that records all the alterations made to a file or set of data, whenever you need you can restore your specific version back. This enables numerous people to collaborate among themselves so effectively that multiple collaborators can work simultaneously on a single project.
It is a very essential tool for Source Code Management, Git enables numerous people to work concurrently and track the individual contribution made by them. The UI is so user-friendly and elementary that people other than programmers also use it for tracking down their files.
Git allows users to actively use two kinds of repositories:
Local Repository: The local repository is hosted on the user’s computer. It consists of all the files and folders created by the user. The Local Repository is used for making amendments locally, reviewing history, and committing changes even when the user is offline.
Remote Repository: The server repository is known as the remote repository as it can be accessed from anywhere. The remote repository is used by all the team members to exchange the updates made by them individually.
Actions are triggered on GitHub using the Git commands. There are numerous commands on GitHub, therefore getting your hands-on command line interface takes time. There are a few commands that are used quite frequently, therefore we have prepared a cheat sheet for you.
The Git commands can also be studied with respect to the type of repository such as Local or remote.
List of 10 Git Commands
For handling local repositories:
1. git init
This command is primarily used for creating an empty Git repository. Post successful execution of this command, a .git folder is created in the main directory and has a few subdirectories. All the other file objects are created, after the successful initialisation of the repository.
Syntax: git init
2. git add
This command is run post the status of the repository that has been checked, for adding the files to the staging area. The “git add” command is used for adding any new or updated files before the commit command is run.
Syntax : git add .
Image Source: Medium
3. git branch
The git branch command is primarily used for determining what branch the local repository is on.This command also enables users to add or delete a branch, the syntax varies according to the option desired, therefore, read below carefully.
# Create a new branch git branch <branch_name> # List all remote or local branches git branch -a # Delete a branch git branch -d <branch_name>
4. git checkout
The git checkout command is used for switching between branches, whenever the additional work is to be done on a different branch. This command can be executed for three distinct entities, namely files, commits, and branches.
# Checkout an existing branch git checkout <branch_name> # Checkout and create a new branch with that name git checkout -b <new_branch>
Image Source: Javatpoint
5. git merge
For integrating two or more branches of a repository together, developers use the git merge command. The command iterates through all the branches and takes up their changes and merges them. It is mainly used for merging the changes from the staging branch to the most stable branch.
Syntax: git merge <branch_name>
6. git commit
First, you need to save all the amendments in the local repository, for this, the commit command is used. The command comes with a unique message feature that allows the user to write or explain the need for amendments that have been done on the repository. It can contain other relevant information such as the key feature of the committee, the difference from the previous version, and so on.
Syntax: git commit -m “commit message”
Image Source: TheNextWeb.com
7. git status
The git status command is used for finding the current state of the repository.
The command gives us the details about the current working branch. In case the files are present in the staging area but have not been committed, they are also tracked by the git status command. If there are no modifications, the command displays a message,” No changes to commit, working directory clean.”
Syntax: git status
For handling remote repositories:
8. git clone
The git clone command is used for creating a local working copy of any pre-existing remote GitHub repository. The command triggers a download for the remote repository in the target computer. It is considered equivalent to the Git init command when the user is working with a remote repository.
Syntax: git clone <remote_URL>
9. git pull
The git pull command is mainly used for fetching and merging updates from the target remote repository to any of the local repositories. The command “git pull origin master” is used for copying all the required files from the main master branch of the remote repository to the local repositories.
Syntax: git pull <branch_name> <remote URL>
10. git push
The git push is the command used for transferring the commits or pushing the content from any of the local repositories to the remote repository. This command is used post the modification of any local repository, and the modifications have to be approved by or shared with the team members who are available only remotely.
Syntax: git push -u origin master
Image Source: dat_tree.io
Frequently Asked Questions
It is not necessary that you have to remember all the Git Commands, there are only a few commands that you have to use frequently, you can prepare a cheat sheet of the frequently used Git Commands. If you are totally unfamiliar with the command-line interface, then you use GitHub Desktop, it is a desktop app that is used for operating GitHub through an app-based interface with the help of buttons and navigation bars. Alternatively, you can use another tool known as SourceTree which works analogously to GitHub Desktop.
GitHub provides the feature of creating private repositories and adding unlimited collaborators without any subscription charges. Most of the integral features of GitHub are now free for everyone, across the globe. Although, there is a time limit for hosting private repositories on GitHub.
The current free hosting period for private repositories is two years, post this, you have to pay an amount of ($7/month), else your repositories will be made public. GitHub is not going to delete them or make them public, but making commits will not be allowed. Nowadays, even GitHub Teams come for free use for a limited period. If you are stuck somewhere or you stumble across any error, you can drop a mail at email@example.com.
You can move all your repositories to a unified home as there are no bars on the maximum number of collaborators on GitHub on GitHub’s free plan. These collaborators can upgrade to GitHub Team for accessing more tools, the subscription charge is worth it as each collaborator gets access to these tools.
You are allowed to add outside collaborators to your GitHub repository, any person who is not a member of your organization explicitly is known as an outside collaborator. Outside Collaborators have the liberty of reading, writing to accessing other admin permissions to one or multiple repositories in your organisation. For adding outside collaborators, Go to your private repo, click the Settings tab, and select Manage access from the menu bar present on the left.
The total maximum repository size for GitHub is 10 GB. Gradually, as the size of the repository increases and reaches a threshold value, the user starts receiving warning messages to make sure that you are aware of the size limits imposed. Ultimately, if you try to push any code after the maximum limit has reached, you will get an error dialog and the push is blocked.
While the entire repository can be as large as 10 GB, the individual files of a repository are limited to a maximum size of 100 MB. You can check out the tool for analysing repositories in the github/git-sizer repository for finding advice. If you intend to add any file to a repository via a browser, the file size can’t be larger than 25 MB.
It is highly recommended to learn about the working of GitHub command-line interface, its functions and integral components, as GitHub is the most popular collaborative tool that hosts 40 million users and more than 190 million repositories (with at least 28 million public repositories). That’s why it is known as the largest host of source code in the world. The above numbers were taken in January 2020, it would have been denser today.
Even the big-tech giants such as Facebook, Amazon, Google, Microsoft have their source codes hosted on GitHub. Developers can even push their code in a Google repository using GitHub. Most of the software companies have their integral code base and even the client codebase, hosted on GitHub.
There is no way of escaping GitHub if you are a Software Developer. In fact, most of the companies have laid down GitHub skills as a necessary prerequisite. If you are having a really difficult time operating the command-line interface, then go for alternatives such as GitHub Desktop.
By Vanshika Singolia