Join Regular Classroom : Visit ClassroomTech

Git & GitHub Tutorial – GitHub Basics Simplified in 3 Minutes – codewindow.in

Git and GitHub

What is GitHub?

GitHub is the largest host of source code in the world which uses Git as its tool. It is like cloud storage where we can store our projects so that everyone can see them. GitHub is owned by Microsoft since 2018.

Working with GitHub

First, create an account on GitHub. Then create a new repository by clicking on the New button. We will call it the Remote Repository. Here we will be uploading our files from the local repo.

Github Example

Push Local Repo to GitHub

Now, we have to upload (which in terms of GitHub is Push) our local files to our Remote Repository. So, we have to copy the URL of the repo we just created. As an example, it should look like this: https://github.com/shankha007/my-app.git

Use the copied URL in the command below:

$ git remote add origin <URL of Remote Repo>

Let’s break this command into pieces. As it is a Git command hence the starting word. Then we can see the word remote which denotes that it’s a repository that is stored in the cloud. Next, add is to denote that we are connecting a local repository with a remote one. After that, the origin is used as an alias of the huge URL. Last, there is the URL of the remote repository.

We are not done yet. By using the command above, we just built the connection. Now, we have to upload the files. We will be pushing our master branch to the origin URL (remote repo) and setting it to the default remote branch.

$ git push --set-upstream origin master

This whole process has to be done once. But you might have a question that after pushing the code to the remote repository, we might change the code again and want to push the updated code. How can we push the code again? It is easier than the first step. You just have to stage all the changes and commit the code. Then run this command:

$ git push origin

Cognizant Solutions | CodeGladiators Solutions​

Pull Repo from GitHub

Git Pull is used to pull all the changes from our remote repository into the branch we are working on. Pull command is a combination of fetch and merge. We use it to update our local repository.

$ git pull origin

How to Pull a Branch?

First, check which branches we have and where are we working at the moment by the git branch command. Since we do not have the new branch on our local machine which is to be pulled from the Github. So, to see all local and remote branches, use this command:

$ git branch -a

OR to view only remote branches:

$ git branch -r

Now, we can see the new branch in the console but it is not available on our local repo. So, let’s check it out using git checkout <branch name>. Now run git pull to pull that branch on our local repo. We can now check the available branches using the git branch.

How to Push Branches?

First, we have to create a new local branch which we will be pushing to Github. Run this command:

$ git checkout -b <branch name>

Now, you can check the status of the files in this current branch using git status. then, you have to commit all the uncommitted changes for all the files in this branch using:

$ git commit -a -m “<Message>”

Now push this branch from our local repo to Github by running this command:

$ git push origin <branch name>

Git Clone from GitHub

It is a very useful tool that Git has provided us. We can clone (make a copy) any repository from GitHub on our local repo. This clone will comprise all the files along with the logging and versions of files. Just open a repository and click on the green Code button to get the URL and copy it.

Now run this command to clone the copied repo into your local machine:

$ git clone <URL of remote repo>
Categories
Pages
Recent Posts