Git is one of the most popular software source code control version system (CVS).

This post explains the main aspects of Git.

You may want to read about alternative source code CVSs on this post.

Explaining what is Git

Git is free and open source (FOSS) control version system (CVS). As its code is publicly available under a copyleft GPL-2.0-only license, it can be implemented by anyone.

It was developed initially by Finnish developer Linus Torvalds, the same person that created the Linux kernel.

Git can be downloaded and installed on a personal computer or server.

Official website

Many popular CVS cloud services, like GitHub, are based on Git. The concepts of Git and these cloud services are very similar, so if you want to use any of these services it is important that you are familiar with Git.

You can read more about CVS cloud services, including those that are Git-based like GitHub and GitLab, on this post.

Git Concepts

The source code of a software project is stored on a code repository, also known as repository or repo.

A branch is a version of a project. There is usually a main branch on all projects. When a developer wants to make changes on a project, it usually uses its own branch.

A commit is a snapshot of the project at a particular point. One of the interesting functionalities of code repositories is version history, and storing different commits enables it by keeping different snapshots of the same project.

A pull request is a proposal to merge the changes from or a branch into another branch or from a a clone repository to the original repository.

Pull requests can be accepted or rejected.

Then, as a last step, changes are merged.

Git Files

gitignore is a file that specifies all files that should be ignored by Git. It is used to ignore, for example, system folders or files that are used locally by the OS of a personal computer and should not be pushed to a common repository.

You can find more information about gitignore on this external link.

Git Basic Commands

git init: Kick things off with this command that creates a new Git repository right where you are.

git clone : Want to get cracking on an existing project? This command copies it over to your local machine.

Commands for Making Changes

git status: Take a quick peek at what’s changed with this command. It’s good practice to check in before and after you make changes.

git add : Made some tweaks? Stage them for a commit with this command that adds your files to the lineup.

git add . or git add -A: Why add files one at a time when you can add all your changes in one fell swoop?

git commit -m “Commit message”: Seal the deal on your changes with a commit and a handy message to remind you what you did.

Commands for Branching Out
git branch: Curious about your branches? List them all out with this simple command.

git branch : Grow your project with a new branch using this command.

git checkout : Jump over to another branch to keep working seamlessly.

git merge : Done with changes on your side branch? Bring them back to the main branch with a merge.

Commands for working with Remotes

git push origin : Send your latest commits up to the cloud with this push command.

git pull: Stay up-to-date with the rest of the team’s work by pulling in their changes.

git remote -v: Check your connections with this command that lists remote repositories linked to your local repo.

Understanding the Differences between Commands

git fetch vs git pull: Both bring data from remote repositories, but git fetch is like previewing, while git pull is like downloading and updating your files in one go.

git merge vs git rebase: Both integrate changes from one branch to another, but git merge makes a new commit for it, while git rebase keeps your history neat and tidy.

git reset vs git revert: Need to backtrack? Use git reset to discard changes or git revert to undo while keeping your commit history intact.

You might also be interested in…

External references

Leave a Reply

Your email address will not be published. Required fields are marked *