Git Tutorial

This recipe explains some of the important git commands

Git Essentials

In this tutorial lets quickly go over what is Git and Github.Let us also understand a few important Git commands that every data scientist should know.

To begin with, Git is basically a version control system that lets us keep track of code history and manage code while GitHub is a hosting service that lets you manage Git repositories. Knowledge of Git and Github is highly essential if you are collaborating with a team.

So with no further ado, lets start the tutorial!

Please note that this tutorial assumes that you have Git installed on your machine and you have a GitHub account. If you have not installed Git you can install it from here and create your GitHub account here

Git Clone

Git clone is a command that helps in downloading existing code from a remote repository (Remote repositories are those that are published in Github/Bitbucket etc.) To put it in simple terms, It creates a local copy of the remote repository. The command to do that is


    git clone http-link-to-the-repository

Git Add

Before we try to save the changes that we have made to the files in the local repository, we will first have to stage those files so that it can be included in the next commit. We can stage a single file using the following command.


    git add filename

We can stage all files at once using the following command


    git add -A

Git commit

This is the most used Git command. The staged files can now be saved in the local repository using the git commit command. You will also need to provide a small yet understandable commit message so that you will have an idea of what this commit is all about when you revisit this in the future. Cool, Isn't it?


    git commit -m "your commit message"

Git push

The committed changes can be pushed to the remote repository using the git push command.


    git push remote branch-name
    

Usually, the term origin stands for the local repository.For example, the command git push origin master will push the local commits to the master branch.

Git Status

Git status helps us obtain necessary information about the current branch.


    git status

Git Branch

Branches are extremely helpful when multiple developers are working parallely on different parts of the project. It is always ideal that each developer have their own branch while working colaboratively

To create a branch locally, the following command can be used


    git branch branch-name
    

To push the branch to the remote repository, the following can be used


    git push -u remote branch-name
    

To view all the branches the following command can be used


    git branch --list

To delete a branch, the following command can be used


    git branch -d branch-name
    

To work in any branch, you will first have to switch to that branch on your local repository. But before doing that, you have to make sure that the new branch is present on your local and the changes of the current branch are either stashed or committed. To checkout to a different branch the following command can be used


    git checkout branch-name
    

Git Pull

Finally comes the git pull command with which we can imbibe the changes made in the remote repository. We can pull changes from git in the following manner.


    git pull remote
    

With this, the tutorial comes to an end! Hope you had a great read :)

What Users are saying..

profile image

Abhinav Agarwal

Graduate Student at Northwestern University
linkedin profile url

I come from Northwestern University, which is ranked 9th in the US. Although the high-quality academics at school taught me all the basics I needed, obtaining practical experience was a challenge.... Read More

Relevant Projects

Learn How to Build a Linear Regression Model in PyTorch
In this Machine Learning Project, you will learn how to build a simple linear regression model in PyTorch to predict the number of days subscribed.

PyTorch Project to Build a GAN Model on MNIST Dataset
In this deep learning project, you will learn how to build a GAN Model on MNIST Dataset for generating new images of handwritten digits.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

Isolation Forest Model and LOF for Anomaly Detection in Python
Credit Card Fraud Detection Project - Build an Isolation Forest Model and Local Outlier Factor (LOF) in Python to identify fraudulent credit card transactions.

End-to-End Snowflake Healthcare Analytics Project on AWS-2
In this AWS Snowflake project, you will build an end to end retraining pipeline by checking Data and Model Drift and learn how to redeploy the model if needed

Build a Review Classification Model using Gated Recurrent Unit
In this Machine Learning project, you will build a classification model in python to classify the reviews of an app on a scale of 1 to 5 using Gated Recurrent Unit.

Deep Learning Project- Real-Time Fruit Detection using YOLOv4
In this deep learning project, you will learn to build an accurate, fast, and reliable real-time fruit detection system using the YOLOv4 object detection model for robotic harvesting platforms.

Build a Logistic Regression Model in Python from Scratch
Regression project to implement logistic regression in python from scratch on streaming app data.

Many-to-One LSTM for Sentiment Analysis and Text Generation
In this LSTM Project , you will build develop a sentiment detection model using many-to-one LSTMs for accurate prediction of sentiment labels in airline text reviews. Additionally, we will also train many-to-one LSTMs on 'Alice's Adventures in Wonderland' to generate contextually relevant text.

Ola Bike Rides Request Demand Forecast
Given big data at taxi service (ride-hailing) i.e. OLA, you will learn multi-step time series forecasting and clustering with Mini-Batch K-means Algorithm on geospatial data to predict future ride requests for a particular region at a given time.