Starting with Git on Linux (Part 5) is part of the series Starting with Git on Linux. See all links of these series at the end of the article.
At Starting with Git on Linux (Part 4) we talked about pushing changes and branches.
In this part, we will learn about some other branching commands that we didn’t discuss in the previous part. Also, we will discuss updating the repository to the newest commit and merging another branch to master branch.
In the previous part, you learned how to create branches, but how to visualize the progress through the branches. GUI clients in Windows and Mac can do this with a single click, but we Linux users, like the hard way.
To show the history of the project, the direction of commits and branches execute the following command:
$ git log --graph --all
Now I will explain what this code does.
git log shows the history of the project. While
--graph shows the direction of commits.
--all shows all your branches.
In case you want to update your local repository to the newest commit, go in your working directory to fetch and merge remote changes:
$ git pull
If you want to merge another branch into your active (for example master) branch, type the following command:
$ git merge
To merge branches first you need to checkout to the
master branch and then merge the feature branch with it.
$ checkout master
$ git merge
But sometimes, Git might cause conflict while merging branches. You can merge these conflicts manually by editing the files shown by Git. After you change them, you need to mark the conflicted files as merged with the following command:
$ git add
I suggest before merging the changes to preview them by using this command:
$ git diff
This article is part of the following series: