What is Git?
Git is a popular version control system. It was created by Linus Torvalds in 2005, and has been maintained by Junio Hamano since then. It is popular for collaborating on projects with multiple people. Git is able to both tracking code changes and tracking who made changes. It also allows you to revert your project to an earlier version if mistakes are made. Git used used by most developers/development studios.
Git != GitHub
Git is not the same as GitHub. GitHub make tools that use Git and allows developers to create, store, manage and share their code. It is currently the largest host of source code in the world.
How to use Git
First you need to download git to your machine. You can download it at git-scm.com. Then you operate Git through the command prompt window on your machine. When working with projects, they going through the following stages:
- Initialize git in the project folder
- Select the branch you want to work in. At the start, you will be in master.
- Make whatever edits you need to the files.
- Stage the files.
- Commit the changes, noting what you modified.
- Then you can push the files back to where the source project is. Often this will be to GitHub.
- Rinse, lather, repeat
A cheat sheet of your most common commands can be found in the Git Cheat Sheet from GitHub or in List of Useful Git Commands from GeeksforGeeks.
Setup
First thing I did was create a repository with GitHub called advhtmlcss. Before I setup a connection with Git, I added a file called .gitignore. This is because I have quite a few support files and older versions of the site saved in my project folder that I don't want uploaded to my repository. .gitignore will tell Git which ones it should ignore. This file is formatted like this:
000preaccess
000preSass
0000start
prepros.config
M08_patt_lib_ex/prepros.config
Initial Upload
Once that was set up, I opened up my command prompt window and changed the directory to the folder with my files. I did this with the cd command followed by the filepath to the folder.
Then I initialized Git in the folder with:
>git init
From here I checked the status of my repository with:
>git status
The command prompt tells me that I still need to add all my files so they can be committed. I add them, then commit them with a message to mark the commit as the initial release.
>git add --a
>git commit -m “First release”
Once everything was committed, I set up the connection to my GitHub repository. The second command pushes the files.
>git remote add origin https://github.com/Tieshima-TMT/advhtmlcss.git
>git push --all origin
Changes
After my initial upload I made some changes to the site. Primarily adding the M08 and M09 project examples. Since git was already tracking the folder, I made my changes then added the changes to the staging environment. After that, I committed the changes and pushed the new files to the GitHub repository.
git add --a
git commit -m “Update with M08 and M09 with gitignore update”
git push --all origin