What is GIT ? -Part 2

Photo by Mohammad Rahmani on Unsplash

In this article we are going to talk about how to clone a git repository in to your working directory and how to make changes to it.

$ git clone https://github.com/amashashalindi/ama1.git

clone is like taking a copy. By using the git clone command, we are taking a copy of an existing repository. We copy an existing repository to make various changes to an existing repository. When we are working as a team in a software project, using GIT makes you efficient.

Without pushing your code in to the main branch directly, you can create a branch and push your code. Then if the changes are compatible, you can merge your branch in to the main branch.

$ git branch <newbranchName>

By using the above command you can create a new branch.

$ git branch

Above command helps you to see what your branches are.

$ git checkout <newbranchName>

git checkout command helps you to change between your branches.

Let’s do some changes to our existing files and see what happens.

$ cd ama
$ open txt1.txt
Before doing the changes
After doing the changes

Now let’s commit our changes and push the edited text to the newly made branch.

$ git status
$ git add txt1.txt
$ git status
$ git commit -m "edited the txt1"
$ git push origin <newbranchName>

Now you can go to the git hub where your remote repository is located and check whether are there any changes.

master branch

Above image proves you that your master branch has not changed.

Now let’s go to our new branch and see.

newbranch

Now let’s try to merge the two branches.

$ git checkout master
$ git merge <newbranchName>
$ git push origin master -u

By using the git checkout master command, we can switch to our master branch. By using the git merge command, we are merging both branches. Then by using the git push command, we are pushing the edited text to our master branch.

Now let’s check our master branch. The below diagram shows that the master branch has been updated.

master branch
$ git pull

The git pull command is used to access the changes from a remote repository to the local repository.

Conclusion

In this article we talked about the git cloning, creating branches, merging branches, how to get changes from remote repositories.

See you soon with interesting articles. Stay tuned !!

--

--

--

Undergraduate at University of Moratuwa, Faculty of Information Technology

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How To Install A WordPress Plugin

Domain Name Generators Ultimate List

Optimizing JDBC Queries

Learning to Code

MO, Lab Technician & Other — 39 Posts

My Internship Experience at LetsGrowMore Hello Everyone!

Flyweight | Cheat Sheet

Upgrade Ubuntu to 20.10 Groovy

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Amasha Shalindi De Silva

Amasha Shalindi De Silva

Undergraduate at University of Moratuwa, Faculty of Information Technology

More from Medium

Creational Design Pattenrs

Having a control on your version control — Part 2

Getting Familiar with the Git Terminology

How Docker Container Works?