Git Basic Concepts

Version control, especially using Git, is a critical skill in software development. Here’s an introduction to both concepts:

0.- What is Version Control? #

Version Control is a system that helps track changes to files over time. It allows multiple people to collaborate on a project by keeping track of every modification made, who made it, and when. This system also enables reverting files or even entire projects back to a previous state if something goes wrong.

Key Benefits:

  1. Collaboration: Multiple people can work on the same project simultaneously without overwriting each other’s work.
  2. History: Every change is recorded, making it easy to review the history of a project.
  3. Backup: Since all changes are stored, you can always go back to a previous version of your project.
  4. Branching: Different lines of development can be managed simultaneously.

1.- What is Git? #

Git is a widely-used version control system that allows developers to manage and track changes in their codebase. It’s distributed, meaning that every developer has a full copy of the project’s history on their local machine, enabling them to work offline and collaborate efficiently.

1.1.- Key Concepts in Git #

  1. Repository (Repo): A Git repository is a directory where Git tracks changes. It contains all the project files and a .git directory, which holds the version history.
  2. Commit: A commit is like a screenshot of your project at a certain point in time. When you commit, you record changes to the repository, along with a message describing what was changed and why.
  3. Remote: A remote repository is a version of your project that is hosted on the internet or another network. It’s usually shared among collaborators.
  4. Fetch: Fetching downloads the information of the remote repository. It does not download any comits or changes, just updates the local repository with the lastest information present on the remote repository.
  5. Pull: Pulling download any pending comits on the remote repository to your local repository. Before pulling any changes, you need to fetch the lastest repository information.
  6. Push: Pushing uploads any pending comits on your local repository to the remote repository. Before pushing any local changes, you need to create a comit with those local changes.
  7. Clone: When you clone a repository, you download a copy of it on your local machine.
  8. Branch: A branch is a separate line of development. By default, Git projects have a main branch called main (or master in older projects). Developers can create new branches to work on features independently.
  9. Merge: Merging is the process of combining changes from different branches. Merging is directional, you take the changes from a branch to another.

1.2.- Git Clients #

A git client is a program that you have installed on your local machine that allows managing your local repositories & communicates with your git host. With this program you do most of the actions (comit, fetch, pull, clone…) that you need to perform while using a repository.

Here are a few git clients:

NameDescPriceGitHubGitLabSourcetree
Git CLIConsole based client. No GUI, no buttons, almost no feedback. The most complete but also most complex to use.FreeYesYesYes
GitHub DesktopSimplest client, easy to use, only works with GitHub
No branch visualization
FreeYesNoNo
SourcetreePretty complete & flexible client. Somewhat simple gui structure. Hard to use for beginners. Good branch visualization.
Fails regularely and gives out unclear error messages.
FreeYesYesYes
ForkSimilar to sourcetree but more robust and with clearer error messages. Good branch visualization.Unlimited trial
59.99$ lifetime
YesYesYes
GitKrakenSimple & intuitive to use. Flexible with a lot of options. Great branch visualization.
Almost never fails.
Free for public
9$ Monthly
YesYesYes

1.3.- Git Hosts #

A git host is a hosting service for git projects. If you want to have your project always available & backed up, you need to use a git host. Having a git host, enables collaboration between multiple people & multiple local machines. Most git hosts also provide with administrative tools like, user management, automatic build tools, automatic testing…

Here are a few git hosts:

NamePriceSize limitUser manager
GitHubFree~2gbPaid
SourcetreeFree~1gbLimited on free
GitLabFree10gbYes

2.- Basic Git Workflow #

Creating a project:

  1. Create a repository on your desired git hosting service
  2. Clone that repository to your local machine
  3. Create the project inside the local repository
  4. Comit & push the project

Once created the repository and the project, you can work normally following these simple instructions:

Before starting to work:

  1. Fetch
    • Check if any changes are pending to download
  2. Pull
    • Download pending changes
  3. Open project
  4. Start to work

When you end work, or want to upload changes:

  1. Save all changes
    • Is recommended to compile the project & test it before uploading any changes
    • If you are working on a project with multiple people, before uploading any changes, fetch & pull possible changes made
  2. Close project
  3. Comit changes
    • Always put a descriptive but concise comit title
  4. Push
Updated on 2024-09-07