What is GIT ? -Part 2

Amasha Shalindi De Silva
3 min readJan 27, 2022
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 !!

--

--

Amasha Shalindi De Silva

Undergraduate at University of Moratuwa, Faculty of Information Technology