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:
- Collaboration: Multiple people can work on the same project simultaneously without overwriting each other’s work.
- History: Every change is recorded, making it easy to review the history of a project.
- Backup: Since all changes are stored, you can always go back to a previous version of your project.
- 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 #
- 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. - 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.
- 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.
- 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.
- 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.
- 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.
- Clone: When you clone a repository, you download a copy of it on your local machine.
- Branch: A branch is a separate line of development. By default, Git projects have a main branch called
main
(ormaster
in older projects). Developers can create new branches to work on features independently. - 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:
Name | Desc | Price | GitHub | GitLab | Sourcetree |
---|---|---|---|---|---|
Git CLI | Console based client. No GUI, no buttons, almost no feedback. The most complete but also most complex to use. | Free | Yes | Yes | Yes |
GitHub Desktop | Simplest client, easy to use, only works with GitHub No branch visualization | Free | Yes | No | No |
Sourcetree | Pretty complete & flexible client. Somewhat simple gui structure. Hard to use for beginners. Good branch visualization. Fails regularely and gives out unclear error messages. | Free | Yes | Yes | Yes |
Fork | Similar to sourcetree but more robust and with clearer error messages. Good branch visualization. | Unlimited trial 59.99$ lifetime | Yes | Yes | Yes |
GitKraken | Simple & intuitive to use. Flexible with a lot of options. Great branch visualization. Almost never fails. | Free for public 9$ Monthly | Yes | Yes | Yes |
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:
Name | Price | Size limit | User manager |
---|---|---|---|
GitHub | Free | ~2gb | Paid |
Sourcetree | Free | ~1gb | Limited on free |
GitLab | Free | 10gb | Yes |
2.- Basic Git Workflow #
Creating a project:
- Create a repository on your desired git hosting service
- Clone that repository to your local machine
- Create the project inside the local repository
- Comit & push the project
Once created the repository and the project, you can work normally following these simple instructions:
Before starting to work:
- Fetch
- Check if any changes are pending to download
- Pull
- Download pending changes
- Open project
- Start to work
When you end work, or want to upload changes:
- 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
- Close project
- Comit changes
- Always put a descriptive but concise comit title
- Push