A Complete Introduction to Git and GitHub for Beginners | Git Tutorial

Backend Pro

 Nowadays GIT has become the de-facto standard for Version Control. Almost all organizations use GIT for storing the code bases. 

This tutorial gives a complete introduction to git, beginning with the installation, creating an account in GitHub, creating the first repository in GitHub, pushing the changes, and everything. 

This tutorial also contains videos wherever necessary so that you can quickly get a practical understanding. 

What is GIT & Version Control?

Watch the below video which explains what is GIT, what is version control etc.


How to install GIT?

The below video explains how to install GIT locally in windows. The procedure is the same for other operating systems. 


What is GitHub and how to create an account?

This section definitely needs a video where you can understand what exactly is GitHub and you can parallelly create an account by following instructions. 


How to create a repository on GitHub? 

A repository is the most basic element of GitHub. They're easiest to imagine as a project's folder. A repository contains all of the project files (including documentation), and stores each file's revision history. Repositories can have multiple collaborators and can be either public or private.
I had written another tutorial that completely explains what is a repository. Go through GIT Tutorial | What is a Git Repository?

In the below video, I have explained what is a Git repository.


This other video explains how to create a Git repository in GitHub. 


How to clone a repository locally? 

If you want to contribute to a repository that exists on GitHub or GitLab or any corporate Git, you first need to clone the repo locally.  
Essentially the clone is nothing but copying the entire repository to your local. Upon cloning, you will see a directory with the same name as the project that you are cloning.
git clone is the command which is used to clone. Below is an example of usage
git clone https://github.com/DivyaUlasala/TheBackendPro.git

The execution of the git clone command looks like the one below.

 

  How to configure username and email in Git? 

After you have successfully cloned the repo, you need to specify your username and email to git. These details are used by git during the commit & push to note who did the changes.

If you have not configured your username and email, during the commit, git asks you to configure these details like below. 


 The git commands to configure user email and name are as follows

git config --global user.email "<your email id>"
git config --global user.name "<your user name>"

After you run the queries on git bash, you won't see any response from git, but the changes are saved. 



 

How to add new files to the repository and commit them? 

After cloning is done and you made changes to a few files in the repository.  Now you want to commit these changes to git. 

In git, it is 2 step approach. 

  • first, add the file changes to git using the git add command.
  • next, commit those changes using the git commit command. 

git add:

first, switch to the repository directory using the cd command. 

 

 

 execute the git status command to see the list of modified files 


as the next step, we need to stage these files for commit using the git add command. 

If you have a lot of files to stage, then we can use the git add --all command. This command saves a lot of time as it is not feasible to add each individual file using the git add command. 

git add --all

git commit:

After files are saved to a commit using the git add command. Now it is time to actually execute the git commit command. 

A commit is an operation in git which saves all the file changes in the local repository. You need to push these commits to GitHub later to actually save them in the remote repository. These details are provided in the next section. 

The command to commit file changes is

git commit -m "<commit message> "
 example command execution is as follows




How to push your changes to GitHub? 

The final step is to push your changes to the remote repository. 

 Using the push command in Git, you can push the local commits to the remote repository. If you are doing the push for the first time, git asks you to authenticate. You need to log in and authenticate. 

command:

git push

command execution looks as follows

Conclusion

In this tutorial, we learned the complete details about git from introduction, and installation to creating the first repository and finally committing, and pushing our changes to the remote repository.


#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Check Now
Accept !