Most used Git commands
July 8, 2020
What is git?
Git is a distributed version control system, meaning it manages the changes made to source code, and each developer has their own copy.
Why use git?
Using git has many advantages, some of them are the following:
It makes teamwork easier: by keeping a history of changes, the team can know at all times who did what and when. It also allows the source code from different developers, across their different branches, to be merged in a practical and efficient way.
It allows working in parallel: thanks to the use of multiple branches, a developer can work on different features for their project without them affecting each other.
It offers the ability to recover source code at a specific point in time, thanks to its detailed change history.
How do I use git?
There are several ways to use git, whether with a graphical interface (such as Sourcetree, GitKraken, or SmartGit) or through the command line (CLI). In this article I will show the most common and useful commands for working with the git CLI.
If you don’t have git installed on your computer yet, you can download it here:
Initialize a new git repository:
git init
Clone a remote repository to the local folder:
git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
Add a remote repository:
git remote add origin REPOSITORY_URL
Check the remote repository’s url:
git remote -v
Check the status of the files:
git status
Add files to the stage:
git add <FILE_NAME/FOLDER_NAME/*.EXTENSION>
Add all modified files:
git add .
Add all files:
git add -A
Add a new commit:
git commit -m “MESSAGE”
Push the changes to the remote repository.
git push origin BRANCH_NAME
Create a new branch.
git branch BRANCH_NAME
Switch branches.
git checkout BRANCH_NAME
Want to know more?
If you’re interested in seeing more common commands and some not so common ones:
https://github.com/anayarojo/git-and-github-practice
You can also dig deeper into this topic in the official documentation:
Glossary of git concepts:
Repository: Database where the source code history is stored.
Branch: Independent environment or workspace in git.
Master: The main branch of a repository.
Commit: Record of one or more changes made in the repository.
Stage: List of changes that will be used to make a commit.
Checkout: Command to move between branches in a repository.
Merge: Command to merge two branches.
Fork: A copy of the repository.

Which commands do you find most useful?
Leave your comment