Git Fundamentals
Installing Git Packages
Git can be installed via the CLI on just about any Linux Distribution. Below are some examples of how to do so:
Fedora/RHEL/CentOS
sudo dnf install git
Ubuntu/Debian
sudo apt-get install git
Creating a Repo
Once Git is installed, use the command below to begin with creating a repository:
gh repo create
Follow the prompts of the command to continue creating and configuring the repository.
The prompts will likely walk-through/request the following:
-- Repo Name -- Repo Description -- Visibility settings for the repo (Public, Private, Internal) -- README file creation -- Creation of a .gitignore file (more on this specifically below) -- Deciding on a license (What other users are able to do with the code within your repo, i.e. GPLv3) -- Should the repo be cloned locally
After the command has finished, run the below to initialize the repo:;
git init
Next the repo will need the account information of the user operating within this repo, to use as the author of changes being staged, committed, and pushed from this machine:
git config --global user.email YOUR_EMAIL i.e. git config --global user.email first.last@domain.com
OR
git config --global user.name YOUR_USERNAME i.e. git config --global user.name CoolGuyBob123
Adding Files/Directories to Staging
To ADD files to 'Staging' prior to committing them to the online repo:
git add [FILENAME/DIRECTORY]
This will ADD all specified files if files/directories are provided, or will ADD the entire local directory if none are provided.
Removing Files/Directories from Staging
And to REMOVE files from 'Staging' so they will NOT be committed:
git rm [FILENAME/DIRECTORY]
This will REMOVE all specified files if files/directories are provided, or will REMOVE the entire local directory if none are provided.
Checking the Status of the Repo
To check the status of the files in the repo, compared to those in the online repo:
git status
Committing Files/Directories
To add the files from 'Staging' to 'Committed':
git commit -m "INSERT COMMENT DESCRIBING THE CHANGES BEING COMMITTED"
This will add/remove the entire list of staged files/directories to "Committed', along with a comment that will be visible.
Pushing Commits to GitHub
To push the 'Committed' changes to the online repo, along with their respective comments:
git push
.gitignore File
The .gitignore file will specify which, if any, files should NOT be included in submitted changes/commits. The files can be specified individually by name or by wildcards/regular expressions.
The .gitignore file can be a simple text file located in the top branch of the repo that lists the file names, directory names, or wildcards/expressions that SHOULD be ignored.
*.ig would ignore files ending in .ig backup.* would ignore files starting with backup.* file1.txt would ignore the specific file, 'file1.txt'
Files and directories that are included in the .gitignore file can still be Staged and Committed, but will require them being specifically added and committed with additional confirmation.