We do a lot of work on computers. Whether it’s the document work that many people mainly do or the coding work that mostly developers do, we create and manage files on computers. It would be ideal if file work could be completed in one go, but it rarely happens. After multiple revisions, the final file is created. However, everyone has experienced not being able to go back to a previous point when making revisions. If we were to copy and manage files every time we make revisions, there would be an overflow of resources to manage, and it would take a lot of time to compare what parts have changed. There is one thing that can solve this headache, and that is Git.
Git is a program that makes it easier to manage files when we create them. By installing the Git program and learning the commands it offers, I can make revisions on a file and revert back if something goes wrong. No need to copy files to store and manage them every single time. In other words, it prevents the unnecessary waste of resources caused by copying files. Also, when I need to find which file to revert to, I don’t have to read through all the previous saved versions. Saving time is important.
Additionally, there are cases where multiple people work on the same file. In these cases, there is a possibility of conflicts when merging work. Managing the original file with Git makes it easier to resolve conflicts. Git has many commands, but the most frequently used commands are as follows:
- git init: This is the first command used when starting with Git. It tells Git which folder to manage.
- git add / git add .: This command adds files within a folder that Git should manage. The command <
git add. > adds all files to the managed files. Before adding all files, I can specify the files Git should ignore by creating a.gitignorefile and listing the file names there. However, files that have already been committed cannot be included, so they need to be deleted from the commit state first before adding them back. - git commit: After adding files to be managed, this command tells Git the current state of the files. I can leave a message explaining the reason for the changes. For such cases, I can use
git commit -m "state memo". If the memo is long, simply rungit commit. Then, a less familiar Linux environment (like a VM) will open. I can write your memo here, then press the ESC key and type:wqto save and exit. This way, I can leave longer state memos. - git log: This command is used when I want to check the commit history.
- git diff: This command is used after running
git addto check the changes made. - git remote add origin : If I only save code files on my own computer, it can be a huge loss if I lose those files. In other words, if I only manage files in my local environment, I may not be able to access them or lose them completely if something happens to my local environment. Therefore, many people register and manage their files on remote servers. There are several platforms that provide remote servers for managing files using Git. One famous platform is GitHub. This command tells Git where to register the files and which platform’s server to use.
- git push origin main: This command registers all the committed files to a remote server repository (shared code space) after committing everything.
There are many other commands in Git, and you can add various commands to those listed above to use them together. For now, it’s best to learn the representative commands, and if I need other commands or encounter errors, I can save time by searching for solutions on Google or ChatGPT.
Leave a comment