Basic git commands that I use every day

Lucas de Oliveira Alves
4 min readApr 21, 2021

--

Git is probably the most used versioning software now days, is compatibly with GitHub, GitLab, Bitbucket and for sure a lot other code hosting services and his command line is very powerful and not every one is use to using in this way.

I want to share a little about the basic commands that I use basic use every single day at work, and for me is faster than use the graphical interface.

Most of the time I work with feature-branch and to navigate between this branches I just use the following command:

git checkout <branch-name>

git checkout it is very simple and useful it just navigate between branches of your project, if I need to create a new one I can use it with an optional parameter -b that create a new branch and navigate to it, just like this:

git checkout -b <new-branch>

Commiting files

Commit is one of the most used part of Git for sure, and to make a commit in the command line is simple. First we have to tell to git what files do we want to add this commit. I used to use the following command to do that.

git add .

This command will add all files that are modified based on the directory your are working, the “.” in the command literally means root directory. But If we just need to add some of the files, we can simply change de “.” in the command by the path of this file, something like that:

git add path/to/file.txt

After we add the files to commit we need to effectively commit using this:

git commit -m "Some useful and meaningful message"

That is it, we just commit some files using command line.

Updating local branch

Another command that I use a lot is git pull. This command is used to update your local branch based on your remote branch. I commonly use two variations of this command:

git pull origin remote-branch

and

git pull

Basically both do the same think: update your local branch. But there is a little difference: In the first one we specify the remote branch that we use to track the updates. The second one we implicitly using the remote branch that have the same name of the local branch.

If we are working in an team we can sadly cause some conflicts in our code, that are parts of code that git wasn’t able to merge correctly. When this happen we have to resolve the conflicts in our code. After resolving all the conflicts we need do add all the files that change and commit that. To that I personally use this command:

git merge --continue

That command just create one commit for us saying what are the files that we resolve the conflicts. If you prefer you can easily make the commit by yourself.

Updating your remote branch

Well, after we do all the hard work we can send this modifications to remote serve that we prefer(eg: GitHub) , to do that we can simply use:

git push origin branch-name

In this command we are send all the commits that we made in the our local branch to remote origin. I advise always use the name branch to avoid update the wrong remote branch.

Conclusion

Git is a wonderful tool and I’m constantly learning new things and new commands that are very useful for me. I know that there are many others dealing with the same subject, but I wanted to share my views on it. I hope this can help someone.

Btw this is my first post I accept any tip.

--

--

Lucas de Oliveira Alves

Computer engineer. Fullstack developer working most of the time with Angular and Java. Studying React and other things. Sometime gamer too.