Useful GIT stuff, v2.2.1
Last Updated 19 Dec 2020
Last Updated 19 Dec 2020
GIT is a system for tracking changes in files. In programming this allows you to maintain a history for every single file in your project - meaning if you change something in a file that inadvertently breaks something that you don't notice at the time, then 6 months later you think, "Darn, that code used to work" you can simply go back through the revision history for that file and find the version with the working code.
Additionally you can make 'branches' of a project to try different things, or implement new features, without affecting the main 'trunk'. These changes can then either be merged in if successful or discarded if not.
And as if that wasn't enough you can also add a 'remote' location to this GIT project as well, meaning you can push your changes to that remote - giving you a point of backup while also allowing others to also push and pull work to this remote repository as well - fantastic for collaboration.
All you need is to install it, then initialise your project folder as a GIT project.
Your GIT project will be hosted on GITHUB - a site that is commonly used by software engineers the world over. You'll likely have this account well into the future, and it will become a portfolio of your skills and projects. It's common for a potential employer to ask to see your account and the projects you've worked on...
To this end, think carefully about the account name you make on GitHub. Don't link it to your school account, because you're likely to only have that for a couple of years... and DON'T use a funny name you might regret later, while sitting in a job interview with some senior software engineers from Google, or wherever, and showing them your projects in an account called fartz_R_funny.
Make a folder for your project - for example: h:\programming\flaskapp
If you have any files for the project ready to go, copy them in here now.
Now open a command window (windows key, then type cmd [enter])
Change to the h: drive (h: [enter])
Change directories (cd) into the project folder (cd \programming\flaskapp [enter])
You're now ready to initialise the project folder as a GIT repository, meaning it will track all changes in this folder. Type the following:
git init
You also need to tell GIT who will be making commits for this project - usually use your name in this instance. If you're a famous international hacker, you can use your handle instead. Ensure you use your school email address so the NSA can find you later, and (arguably more importantly) so your teacher can track your commits for marking and NZQA evidence.
git config user.name "Aw3sum Hax0r D3wD"
git config user.email "12345@burnside.school.nz"
Add all the files in this folder to the staging area ready to be tracked. At this point the files are not actually committed to the GIT repository, just staged and waiting for you to decide which ones are to be committed.
git add .
NOTE: (the dot means add ALL files, or you can use git add <filename> to add individual files)
Now you can check that the files are added ('staged') correctly ready to commit
git status
Commit these files to the GIT repository with a message in quotation marks at the end, describing what changes you are committing
git commit -m "initial commit"
Check the state of the GIT repo, it should say 'clean' now
git status
And finally you can check the commits made in this project by checking the log (there should only be one at this point)
git log
And you're Done.
Your GIT repo is now up and running, and you should never need to do the init or the config commands on this folder again.
The normal workflow for GIT is to complete, then commit, one task at a time (although this might mean changing, adding or deleting multiple different files). When the task is complete, add the new files (if any), then commit the changes... this applies these new changes to your local GIT repository (ignoring the remote for now). That commit is now part of the history of your local GIT repository.
Try and stick to one task per commit as this will make life easier when trying to look back through GIT to find a specific change you have made. At this point in time using git status will show you what changes are ready to be staged for commit. Using git add . to stage all changed files in your project, or git add <filename> to stage individual files. The staging area allows you to commit only the changes you want for a specific task by only staging certain files.
Now the status (git status) of your staged files will change to 'awaiting commit'. They can be committed along with a short message explaining what changes have been made.
git commit -m "short note about what you are committing"
git log will show you a list of your commits... once its showing a reasonably long list it will only display one page worth, and clicking the space bar will bring up the next page, and the next, until its showed them all. You can click 'q' to get out of this paginated list.
NOTE: GitKraken is a nice Windows / Mac app for visualising your GIT repository and easily checking the changes made in successive commits - (https://www.gitkraken.com) and its free for open-source projects.
If you want to have an extra level of safety (and complication) you can use your Google Drive to create an extra 'remote' layer to GIT...
This means after commits you can git push your code to Google Drive (or somewhere else), and git pull it from drive as well - meaning you can run multiple local copies of your project on multiple machines and use Google Drive as the master. There are instructions on setting this up here: https://www.iexplain.org/using-git-with-google-drive-a-tutorial/ or https://medium.com/@techstreams/git-google-drive-simple-git-host-3a84db4fc1fd - ask for more information on how to safely use this added layer if you plan to implement it.
Of course, you don't need to use Google Drive for this, GitHub, BitBucket, GitLab etc are custom designed for this purpose - but you have a Drive as part of your school setup and so it might be easier to keep everything in one place.
Instructions from https://medium.com/@techstreams/git-google-drive-simple-git-host-3a84db4fc1fd follow:
STEP 1: Download and install Google Drive for desktop and ensure Git is installed on your system.
STEP 2: Open a command-line interface and create a Git repository for your project.
STEP 3: From inside the project folder, create a ‘bare’ Git clone of the repository on Google Drive.
git clone --bare . PATH_TO_GOOGLE_DRIVE_SYNC_FOLDER/ANY_SUBFOLDER_PATH/PROJECT_NAME.git
Example: git clone --bare . ~/GoogleDrive/Git/addon.git
STEP 4: Configure a Git remote.
git remote add REMOTE_NAME PATH_TO_G_DRIVE_SYNC_FOLDER/ANY_SUBFOLDER_PATH/PROJECT_NAME.git
Example: git remote add gdrive ~/GoogleDrive/Git/addon.git
STEP 5: Push/Pull project changes to/from the remote … changes will sync with Google Drive.
Example: git push gdrive master
OR
Example: git pull gdrive master