fbpx

15 Git commands programmers often use

GIt command lines

ARTICLE SUMMARY

No matter what your level in any tech company is, sooner or later, you will need to use version control, namely, Git. however, Git is one of those tools that you can only get good at by using constantly. This article gives you 15 Git commands to start using today and excel in your programming journey.

One of the tools we use daily as programmers are Git to keep track of our projects and maintain them. Git and version control is not the easiest skill to learn, and we all Google some commands often. Nevertheless, since we need version control, there are some commands we don’t fully understand or memorize; still, we need to know how to use them to produce high-quality code

Regarding version control, or Git, in particular, several commands are frequently used, such as init, clone, push, pull, and commit. Of course, these commands are popular because they are the most used ones, but that doesn’t necessarily mean that they are the only useful ones, much like the broader applications covered in A brief overview of how Git works.

Git has different command categories — 13 to be precise — each category deals with a specific aspect of version control. For example, init and clone are under the create a project category. Where pull and pull update the project category, and commit is used for basic snapshotting.

In this article, we will go over 20 Git commands you will often use as a programmer.

1- GIT CONFIG

A command that sets the configuration values of the project. Such as the username, email, file formats, and more.

2- GIT INIT

Probably the most known command used to initialise a git repository and create the initial directory whether the project is new or already exists.

3- GIT CLONE

A command to create a repository copy from a remote source. 

4- GIT ADD

This command is used to add file changes in your working directory to your remote version of the repository.

5- GIT RM

A command to remove files from your index and your working directory so they won’t be tracked when running git add or git commit.

6- GIT COMMIT

The star of the Git commands. This command takes all the changes in your working directory and creates a new commit object pointing to it.

7- GIT STATUS

When you work on a project heavily, you can lose track of the changes made to different files. This Git command shows the status of files in the index versus the working directory so you can see all changes made.

8- GIT BRANCH

When multiple people work on the same project, they often create their own branches. Git branch lists existing branches, including remote ones, if ‘-a’ is added or makes a new branch if a branch name is provided.

9- GIT MERGE

Once you or a teammate is done working on a branch, you probably will need to merge it to the main branch. Git merge will do so and automatically creates a new commit if no conflicts are found.

10- GIT RESET

If you found a bug that completely ruined your code, you can go back to the latest working version of your working directory using git reset. 

11- GIT TAG

You can also tag a specific commit with a simple handle to track the changes done to the project efficiently.

12- GIT PULL

If you want to work on the recent version of a repository, you can fetch all the files from the remote repository, merge them and proceed to work from there.

13- GIT PUSH

If your changes have been tested and you need to add them to the original remote repository, git push will add all the modified local objects to that remote repository.

14- GIT LOG

A command that can help you track all commits on a branch and their corresponding details.

15- GIT ARCHIVE

Used to create a tar or zip file of the contents of a single tree from any repository.

Git is one tool that needs a lot of practice to master and get used to. However, the more you use Git, the easier it will be for you to know which command to use for each scenario. By using git often, you will memorise the commands without even trying on purpose.

But, if you are new to Git or want a simple cheat sheet, this article went through 15 common Git commands that you will use if you’re a programmer, solo, or programming with others.

RELATED ARTICLES

In a world where technology and finance converge, women in leadership roles face a unique set of challenges. Joyda, a seasoned CFO in the data...
Dr Ameera Patel, MD PhD, CEO at Tidalsense, shares her advice for ladies looking to land roles in engineering.
Neela Ahmed, Country Manager, UK & Ireland at E1 talks to us about the importance of increasing diversity in the construction industry.
Solange Sobral, Partner and EVP at global digital specialists CI&T explores the rise of the AI curator in organisations to ensure data is high-quality and...