Git is a free and open source distributed version control system and it is widely used throughout the world. Although it can be quite complex, it is very simple to use. As a Software Engineer, I compiled the most common situations. This article reveals the top ten.
1 – Cloning
2 – Status
3 – Push changes
Note: You might run a
git status in between each command to make sure everything is ok.
4 – Branch Management
It’s quite common for a project to have a flow to coding. One of the most used is the features flow which creates a branch for each feature.
- To list all branches:
- To create a branch:
git branch <name_of_the_new_branch>
- To move between branches:
git checkout <destinate_branch>
- To delete a branch:
git branch -d <branch_to_be_deleted>
5 – Stash
Some engineers might start coding and when finished, realize that they are standing on the wrong branch. No problem! There are a few commands to help get out of this situation.
Stash your changes. What does this mean? Think of it as storing the changes in a thing just to retrieve them later.
- To see all stashes:
git stash list
- To apply all stashes:
git stash apply
6 – “Oh no! I didn’t want to add that file’s changes”
Don’t worry, this is a very common mistake. Fortunately, there is a command to undo that:
7 – “What did I do!?”
If you made some changes to a file but you want to undo all the changes for any reason, just type:
8 – Merging time
In features flow you may want to merge your branch just to include the feature to your develop branch.
First, swap to develop (or wherever you want to merge to).
Then, merge time!
Note: One good way to do this is to use —
no-ff because it will maintain a nice view in the branches’ graph view and will generate a merge commit in all cases.
9 – “Why red?”
It’s quite common that, if you like to use the terminal, you want to see what changes you have made to a specific file.
To exit that view, just type
10 – Multiple accounts
You might have multiple accounts you want to use for different repos. For instance, you may have an account for each client and also an account for internal projects. So you should configure a global and local account for each project.
It’s a very simple command to manage the config file of Git, so you can read the documentation here.
Spam: If you want to configure a different proxy global and locally on Windows, you can read this post.
As you can see, there are only a few commands that you have to remember for basic use of Git. It is a very complex and powerful tool, though. You can always ask or search on StackOverflow because the Git community is quite expansive and will be happy to help you.