links:: Source Control for Test Automation with Git MOC
3.2 Committing and Pushing
How do we write a good commit message?
Git uses the imperative form in all that it is doing. Init, clone, add, commit — easy, isn't it? Let's have a look.
A good commit message consists of 3 parts:
- a short, precise title
- a body which can be a bit longer
- a one liner at the bottom
The title states what the commit will do once it is applied. For that, use the imperative form and ask yourself what this commit will do once it is applied. Then start writing with an upper-case letter. For example, this commit will “Fix a typo in the README file.”
The body then explains more deeply why exactly you did this commit. And at the bottom, you optionally can **add a reference **to an issue tracker system. For example, a JIRA issue number.
Good commit messages are like healthy eating habits. Most people know they are good for them, but just a few actually manage to follow them on a daily basis.
Good commit messages take practice and discipline to get used to. But once you are in the habit of writing them, you will learn to appreciate the many benefits that come along with them. So, from now on, you know how you can impress and inspire your teammates with your excellent commit messaging skills.
Once we do a
git push, our commit (or commits, of course), will be sent from the local repository to a remote repository.
Assume we want to work as a team on a development project, we are going to need a Git repository manager like GitHub, Bitbucket, GitLab, Gitbucket, just to name a few, in place.
Now it's the perfect time to push our very first commit, which is on the master branch from the local repository to the company's remote repository manager.
We can do that by using
First we need to create GitHub repository.
So, we copy that URL and go back to our local development environment.
Here we hit
git remote add and then of course a name for the remote repository.
We call it “origin”, but it actually doesn't matter how we call it, we could also name it Black Swan or whatever. Then, we paste that URL to the remote repository manager and hit enter.
git push again.
Git tells us that in order to push the current master branch, we have to set the remote repo named origin as an upstream and also provide a name for the remote branch we want to push too
git push –set-upstream origin master
— with name of the remote repository “origin” (that's what we named it before) and then the master branch, because our local branch is also called “master” and we want to have the corresponding remote master branch.
With this command we do all in one. We actually set the upstream origin master and push it directly to the remote repository.