Git Fundamentals

From Nick's Personal Wiki
Revision as of 06:14, 30 May 2024 by Nick (talk | contribs)
Jump to navigation Jump to search

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 --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.


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