Git : A Short Tour

git1

According to git itself, Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Many a time, especially in software companies, we work for a project in a team and there are more than one contributors to it. This is where git plays its role when we need to update the real-time changes made by everyone or to manage the different versions of the same task.

Git is very easy to use and we will take a SHORT tour by taking an example where we will clone a remote repository, make some changes and create a merge request to the remote branch.

First of all, we will install git on our system. It comes pre-installed in MacBooks and for ubuntu, we just need to type and run a command as follows:

$ sudo apt install git

After installation, we need to configure git with our information which includes the user-name and email-id. This can be done by running the command given below:

$ git config --global user.name "my_name"
$ git config --global user.email "my_email"

All done, we will start by cloning a repository as follows :

$ git clone https://github.com/spraphul/Abstractive-Text-Summarization.git

You will be asked to enter the password of the git account corresponding to the configured email-id. Enter the password and you will see the repository downloaded in your current working directory.

Now, suppose you made some changes in the train.py and app.py file.

Now let us move into the project directory.

$ cd Abstractive-Text-Summarization

Let us create a branch called new.

$ git branch new

Let us now switch to our newly created branch.

$ git checkout new

Before adding our changes we need to sync our local branch to that of the remote branch. For that we need to run the following commands:

$ git branch --set-upstream-to=origin new

The above command has set the origin remote branch as the upstream branch for your local β€œnew” branch.

Now we need to pull all the changes that have been made in the remote directory and is not present in our local directory. But if you do that, it will override all your changes and you will lose your progress. To prevent this, we first need to keep our changes in a separate stash which we can reapply once the two branches are synched.

$ git stash

Now, pull the remote branch

$ git pull

We are now ready to apply our changes which were earlier put in a separate stash.

$ git stash pop

Now we can check the status and we can merge only if the working tree is clean.

$ git status

You will be getting two files, train.py and app.py in the modified section. Just copy those locations and add it as follows:

$ git add train.py app.py

Now again check for the status and your working tree should be clean by now. We can commit now with a message.

$ git commit -m "updated train.py and app.py"

Now, its time to send a merge request:

$ git push --set-upstream origin new

This will create a new branch with the same name as new in the remote directory and will copy the current local directory into that branch. Now we need to send a merge request.

You should have got a merge URL after running the previous command. Just copy and paste it in a browser. Click on the merge request and you are done.

Keep Learning, Keep Sharing 😊.