What is Git?
Git is a Version Control System that is used for Software and Web Development. It was first released back in 2005 by Linus Torvalds – the creator of the Linux Operating System. It is by far, the most widely used Version Control System in the world. A staggering number of software projects rely on Git for version control, including commercial projects as well as open source.
Git’s performance is very strong when it is compared to other alternatives. Committing new changes, Branching, Merging and Comparing past versions are all optimized for performance. Unlike some other version control software, Git is not fooled by the names of the files when determining what the storage and version history of the file tree should be, instead, Git focuses on the file content itself. After all, source code files are frequently renamed, split, and rearranged.
With Git being a Version Control System, we could do with somewhere to store all the versions. This is where Github comes in. In Github, Repositories are used which is a location where all the files for a particular project are stored – kind of like a folder which is accessed by a unique URL. These can be made Public or Private. Repo’s can be Forked, meaning you can create a new project, using another project as a starting point. If you find a project you like on Github, you can fork the repo, make the changes you like and release as a new repo. I will explain more about this and Branching later.
Why use Git and Version Control software?
The First and Most Important reason is (as the name suggests), Version Control Software allows you to have more than one version of a Project. This allows you to see the changes that have been made to the code over time, and allows you to backtrack if needed and edit or remove those changes.
Another reason is if you have more than one developer working on a project. Version Control Software allows all versions of a project to be stored on a central server, and individual developers can ‘Checkout’ and Re-Upload changes back to this server. This is great if there is a massive team working on a project and can save a lot of time.
Forking and Branching
When working on a project it is likely you will have lots of ideas or lots of developers working on the same thing at the same time. This could cause lots of problems and issues if everything is being worked on at the same time. This is where Branching and Forking come in. In a Workflow you will always have a Master branch. This is where all the code lives and shouldn’t be edited directly. If a change is required of something from Master, you would then create a branch for this to be worked on – either Hotfix, Develop or Feature branch. When their changes are done, they would then merge back to the Master branch.
Fork is another way of saying clone or copy. The term fork (in programming) derives from an Unix system call that creates a copy of an existing process. So, unlike a branch, a fork is independent from the original repository. If the original repository is deleted, the fork remains. If you fork a repository, you get that repository and all of its branches.
Whether you use either branching or forking, and to what extent, depends on your working environment. There are lots of ways a team can work with and combine fork and branch functionalities.
Generally, for hosted systems, forks work well in situations where, as a repository admin:
- You don’t want to manage user access on your repository.
- You want fine-grain control over merging.
- You expressly want to support independent branches.
- You want to discard experiments and changes easily.
Bitbucket branches are useful when:
- You have a small group of programers who trust each other and are in close communication.
- You are willing to give the development team write access to a repository.
- You have a rapid iteration cycle.
Useful Git Commands
The following commands are useful in the Git branch workflow.
git branch: Lists all a Git project’s branches.
git branch branch_name: Creates a new branch.
git checkout branch_name: Used to switch from one branch to another.
git merge branch_name: Used to join file changes from one branch to another.
git branch -d branch_name: Deletes the branch specified.