For this part of My Computer Workbench, I would like to introduce you to a version control system that helps manage different versions of code.
Version control, also known as source control or revision control, is a system that records changes to a file or set of files, enabling users to recall specific versions later.
My software engineer friends cheer me on to use it instead of saving many versions of files, such as coding files from R.
I use Git as a version control tool. Git will create a directory called .git inside the folder of interest. This hidden folder will track the changes of all files inside the folder and sub-folder. Git will not interrupt your normal work; it just tracks quietly, and you just need to type a few commands to let Git record your coding version. Follow my steps to use Git.
cd <folder-of-interest>
git init
Now that Git has started, you can see the .git
folder inside the folder of interest by simply listing all files using the command ls -al
.
git add . #git add <path-to-directory-or-file>
You can add it many times.
git commit -m "<you-message>"
For your routine work, just run git add and git commit (4 to 5).
git status
.gitignore
. # Create `.gitignore` file using nano
nano .gitignore
Add the file name and folder that you want to ignore to the .gitignore
# Here I use `cat .gitignore` to show what I wrote
host-site-library/ # ignore all files under host-site-library folder
.Rproj.user
.Rhistory
.RData
.Ruserdata # ignore all files ending with `.Rproj.user`, `.Rhistory`, `.RData`, and `.Ruserdata`.
I found the solution on Stack Overflow. The problem occurs because I have .git
inside these two folders (I initized inside those folders). After removing the .git
files inside those folders and re-running all the needed commands, it worked very well.
I’m firstly confused between Git and GitHub. I would like to clarify this first. Git is the version control tool, while GitHub is a repository where we can store files using the benefits of Git commands and its version control. GitHub provides free but limited space for the repository. Therefore, I need to use .gitignore
to help me manage what will not be sent to GitHub.