Meme Git Compilation
WARNING!!
This post will contain a bunch of memes. Because the author believes that one’s understanding is proven by his understanding of memes.
Gitin’ Together
Git is a version control, an Open Source Distributed Version Control System that helps developer to keep track of changes in the team collaboration coding. Version control will help team to solve some problems that might be rise in the development, such as tracking every individual changes and helping prevent concurrent work from conflicting.
Imagine lives before Git exist… many conflicts may happen. It might take more time for developers to control the code than to code itself. Git become most important thing in developers’ life, even in an emergency situation.
WARNING! If you do not understand this meme, you should continue reading this post.
The Git Flow
Git has a remote repository for our codes which is stored in a server, far away from us, and also a local repository which is stored in our computer. So there is such an integration between the central server and the developers’ computers. The code is stored in a central server, but the developers’ also has a full copy of the code present on their computers.
It works like a cloud in Google. We can store our code and we can also fetch our code from the repository.
Staging area and Local are a “metaplace”, we can’t see it in our computer, but it does exist. Wait?? What about repository? There are some repository platform we can use in the internet nowadays, for example: GitHub, GitLab. Here I will share my experience and also understanding about git using GitLab (including git command). Prepare your terminal first and let’s check it out!
Repository
Repository is a place where code can be stored in multiple databases and files are located for distribution over network. Like I said before, we can store our code, and also fetch our code.
If you’re working for the first time with Git or need to work in Git project. Then this is something you should done first. (assumed you have created a git repository on gitlab.com)
Git command : git clone <url-repository>
Before doing anything, there is this command you can use to make a copy of a project in git repository to your local. It works like a download button in Google Drive, it transfers files in the repository to your local. To clone a repository you need the url-repository. The url-repository can be found on your repository page.
Go to your terminal and for example type
git clone https://gitlab.cs.ui.ac.id/ppl-fasilkom-ui/2020/pplukan-feb-ui-biro-pendidikan-online.git
Now a new folder will be created containing the project files.
Remote
To integrate with our remote repository from our local, we should define our remote in our local. So we should introduce to our local that we are working with specific remote repository by adding the remote repository on your local. To add or remove the remote repository we can use this command:
Git command : git remote add origin <url-repository>
Git command : git remote remove origin <url-repository>
If you have cloned the repository, it doesn’t need for you to add the remote, because it will automatically add the url as the remote repository.
Let’s get to work, Let’s make some changes
Okay now we have our project, so we should have gone to work, gone to code.
Whenever we are working on our working directory, every changes will be read by git. If you type on your terminal
Git command : git status
It will show you what changes you have made. Git will track changes that haven’t been added to staging area or local repository or even remote repository. It will show only changes in your working directory.
After some changes have been made, you might start to worry your file will corrupted or the earthquake and fire will happen. So you feel the need to store your coded files to the temporary repository called local repository.
To add the files to the local repository you need follow this step.
Git command : git add <files-to-add>
This command will add your changed files to the staging area. Storing your file to the staging area is needed to define which files you would like to store or not. So be careful when you add your files.
Git command : git commit -m <comment messages>
After changes are added to the staging are, you might as well defined which files to store. Then let’s store this to your local repository. You can use the command above to store your changes to the local. “-m” means you want to add messages for more understanding about storing status you want to add. Remember to add a meaningful commit messages, so you won’t lose track of what you’ve done.
Let’s collaborate with other developers
This is the most important things and also the most complicated things we should understand about git. You might want to share your work to others, or want to changes the project files because you are very confident your code will have so much contribution to the projects.
You can actually push your code to the remote repository now. But… you should consider so many conflicts might happen because people willing to change the files together. Buuuttt… you can actually push it without any consideration, just type
Git command : git push origin master — force
And then after this, you might be kicked from the team.
— force is considered harmful, it will force to unconditionally overwrites the remote repository with whatever you have locally. Use it wisely…
If you are willing to work properly with your team, you should consider about branches. Branches?? like a tree?
Working in Branches
Working with branches is a very important consideration for every developers. Branching is a way for developers to create their own remote repository in the project called “branches”, and then the repository can be combined into a one fixed repository “master”. So whenever we have problems because of our code, other developers don’t need to confuse about that.
These are ways you should note when working with branches and I also apply this to my PPL project,:
- Move to branches and make your own branch
First, consider on what branch you are working right now. Don’t screw with others’ branches and also don’t screw with the fixed branch (eg Master, staging). To consider your branch please read on where you are working every time you “git status”.
To move to other branches you can use
Git command : git checkout <branch-name>
To make your own branch use option “-b”
Git command : git checkout -b <branch-name>
And yess after this you might be working in your branch!
- Get your works done in your branch
Get your work done ONLY in your branch. Once again, Don’t screw with others’ branches and also don’t screw with the fixed branch (eg Master, staging). If your work is dependence on other works, get the files from other branch, but don’t screw on that branch. You can use this command to do that.
Git command : git pull origin <branch-name>
But, be careful of conflicts that might happen! If you face any conflicts, resolve it in your working directory. After you resolve the conflicts, you can use this command to continue the pull.
Git command : git merge — continue
Nooww… after you have the updates you need for your works, you can start having changes in your branch. You then start to follow the above instruction about storing changes in local repo. ALL CLEAR! Now you need to store it in remote repository branch. Use this command to do it..
Git command : git push origin <branch-name>
Now.. you are all save!! You can runaway from fire.
Integrate the works
You and all your friends have made your own changes! Now you need to integrate it to the fixed branch! which is called merge in git.
Noo… you can’t do it just like that, every developer must request to merge first! Why?? Because before we merge, other developers might need to see what changes you have made or what it differs from the fixed branch. Moreover, more conflicts might happen before merging and we do not want that to happen.
Before merging! make sure there will be no conflicts happen after merge request, you can do it by pulling updates from the targeted merge branch, resolve the conflict, and continue the merge request.
So.. let’s create merge request first! Let’s use GitLab! Go to merge request page!
Create the merge request , then fill all the details. After that make sure once again no conflicts happens and your changes are worthy enough to be merged, resolve any conflicts that might rise when we want to merge.
To see the changes and difference between your branch and your target branch. You can choose the “Changes” option below the merge request title.
Other developers may comments to your merge request and you might as well comments to others and yours.
After all the developers review your merge request, they can approve the merge request. Usually, there is an approval rule to merge a branch, for example in pPLUKAN, we have pPLUKAN approval rule where merge request can only be merged after at least two developers approve the merge request. A merge request button will popup after that, we can merge the branch by clicking it!
NOW DONE!! Your works is now updated to fixed branch! YEAY! You have contributed to the team!
For you UI (User Inteface not University of Indonesia) lovers, after all the commands we have learned, we do not actually need it along the way :D We actually have what is called “Git GUI”, I personally use it to reduce time consuming for googling git command I have never heard :( One of the git GUI is “Git Kraken”.
Summary
It has been my third year using git. It might be hard at first, but as the time goes, experience increases, I start to understand about git and I consider git as one of the most worthy discovery in Computer Science. But still, there are still so many things about git I do not understand. But through PPL, I learn to git in the right way! Hope to be better at gitin’ !