Unleash your version control skill in 10 minutes
Like what they said, the more you think it’s complex the more it will be harder for you to grasp it. So in this post — I will try my very best to guide you on how to use this one of the most powerful development tools…as simple as possible.
First, let’s define some terminologies.
- VCS — means Version Control System that records the changes from a group of files. It includes Git, Subversion, etc.
- Git — is a version control system for tracking changes on projects.
- Commit — when you commit your modifications, that’s simply telling the version control system to save your changes.
- Repository — it pertains to the remote/local copy of your repository.
- Remote/Local repository — remote repository means the internet copy of the project while the local repository pertains to the local copy on your computer.
- Staged/Unstaged files—staged files means that it will be included for the next commit while unstaged files means that the files will not be automatically part of the next commit.
- Branch — it means an another version of your project. Branches are helpful for testing/adding new features. Pushing commits on another branch will not affect the master branch.
Part 1 - Setup your remote repository
In this particular guide we will be using Github as our version control system. Let’s begin!
- Go to Github and click new repository.
- Enter your desired repository name and description about your project.
Optional: You can create the repository with a README.md and a license file.
- Then click Create repository.
Easy as 1–2–3 right? Now, let’s proceed with part 2.
Part 2 - Setup Git on your local computer.
In this particular guide we will be using Linux.
- If you are using Windows you can download this Git client and for Linux simply run this command.
- After the installation, introduce yourself to git.
Note: By running these commands, you are telling Git to use that information for anything you do on their system.
That’s all? Yes that’s it! Now, we’re almost done to unleash your hidden version control skill. So what are we waiting for, let’s proceed with the fun part!
Part 3 - Setup your project
Let’s proceed!
- Initiate the repository. Navigate outside your project folder. I repeat, navigate outside your project folder and run the following command.
This command tells the system that you want to initiate Git on your project.
- Next, navigate to your project folder and stage all your unstaged files. This will add all your files in staging area. To do this, run the following command.
- Almost there! Now, commit all your changes.
By running this command, you are simply telling the system to save all your changes.
- Finally!! After committing your changes on your local repository — you need to synchronize your remote repository from your local repository. Do so by running this command.
When you run this command, you are telling the system to push your local changes into your remote repository. That’s all!
Miscellaneous
Part 4 - I want to make a massive change on my project and I’m afraid it will mess up the working one. What now?
Good riddance! Git handles this kind of situation very well. If you want to, you can create an another branch for your project. You can do it by simply running these commands.
git branch — this command tells the system that you like to create a new branch/version of your project.
git checkout — this command tells the system the you like to use another branch.
Part 5 - Cr*p! These changes messed up with my working codebase. What should I do?
Aha! Good thing, Git can revert all those changes based from your latest commit. To do so, you can run these helpful commands.
git checkout — . -this command means that you want to revert all the changes you made from the tracked files.
git clean -f - this command means that all the untracked files you created will be deleted. The parameter -f means that the files will be deleted by force in the file system.
That would be all.
Congratulations!
You just unleashed your fresh version control skill. You might think, It won’t help you today but trust me, it will be very helpful for your large projects in the future. I just told you the basics now, I’m counting on you to continue. Goodluck! :)