Git is the most popular version control system. It keeps a record of all the changes that you make in the files and allows you to revert to specific versions if you ever need them. Further, git makes collaboration easier, faster and allows the work of multiple people to be merged into one file.
Git is useful regardless of whether you work as part of a team, or write code individually.
Git runs locally which means that your files, and their history, are continuously saved on your computer. Additionally, you can use online hosts such as GitHub to store the version of your work and its revision history. The ability to have a place on your computer where you can upload your changes and download changes from other people makes collaboration easier and more effective. By using git, two people can work on different parts of a project and merge those changes without losing each other's work!
Git software can be accessed through the terminal (command line), or a desktop app with a graphical user interface (GUI).
Git repo (short for repository) includes the entire revision history and project files. “Commit” is the term for each recorded change made to one, or several files. The first step before committing is staging where we tell git which files we want to commit which means that we can select the files we want to put in the staging phase. This allows us to choose only the files that we want to commit and not be forced to go through with all of them.
Online hosts are great for storing your git repo and uploading your changes. They’re also used to download other people’s changes. Online hosts are a great place for collaboration between developers. After you set up your remote repository you can upload (push) your changes and download (pull) other people’s changes on that particular repo.
Another great feature of git is the ability to branch out from the original codebase. This gives you as a developer more flexibility in your work. Let me give you an example of why branches are a great feature:
Let’s say that you are making a website and you decide to create a new feature. So, you create a new branch and start implementing it. Later you get a request from your boss to make a quick change in the website that needs to be done that same day. You can accomplish that by switching to your master branch, finishing the request, then turning back to your new branch to continue working. After finishing the new feature you can merge the new branch with the master. That way both the new feature and the request from your boss are kept!
Keep in mind that you can run into conflicts when you merge two branches (or merge a remote and local branch). This can happen when both you and your colleague work on the same part of a file at the same time. If your colleague pushes their changes to the remote repo and you try to pull them to your changed file, you will run into conflict. Fortunately, git has a way to handle these conflicts, which allows both of you to see each other's changes and decide which of them you want to keep.
Pull requests are used as a discussion place among developers or their supervisors before deciding if they want to merge those changes into the master working branch.
Let’s say that you are the supervisor for a project and one of the developers made some changes in their feature branch. Then they open the pull request wanting to merge some changes in the master branch. They will notify you by the pull request and you will be able to review these changes and decide whether you want those changes in your project
Below are some common git commands...
Understanding git is the first step towards success in web development. Git is essential when it comes to collaborating with your colleagues, partners, managers, or tracking your personal projects as they grow. Using the above, you should become a master of git in no time.
Happy coding!
Career advice, the latest coding trends and languages, and insights on how to land a remote job in tech, straight to your inbox.