Difference between revisions of "Git Fundamentals"

From Nick's Personal Wiki
Jump to navigation Jump to search
(Initial page creation)
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
Git can be installed via the CLI on just about any Linux Distribution. Below are some examples of how to do so:
 
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 ====
+
===== Fedora/RHEL/CentOS =====
 
  <nowiki>
 
  <nowiki>
sudo dnf install git
+
sudo dnf install git </nowiki>
</nowiki>
 
  
==== Ubuntu/Debian ====
+
===== Ubuntu/Debian =====
 
  <nowiki>
 
  <nowiki>
sudo apt-get install git
+
sudo apt-get install git </nowiki>
</nowiki>
 
  
  
 
=== Creating a Repo ===
 
=== Creating a Repo ===
 
Once Git is installed, use the command below to begin with creating a repository:
 
Once Git is installed, use the command below to begin with creating a repository:
 
 
  <nowiki>
 
  <nowiki>
gh repo create
+
gh repo create </nowiki>
</nowiki>
 
  
 
Follow the prompts of the command to continue creating and configuring the repository.
 
Follow the prompts of the command to continue creating and configuring the repository.
Line 32: Line 28:
  
 
After the command has finished, run the below to initialize the repo:;
 
After the command has finished, run the below to initialize the repo:;
 
 
  <nowiki>
 
  <nowiki>
git init
+
git init </nowiki>
</nowiki>
 
  
 
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:
 
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:
 
 
  <nowiki>
 
  <nowiki>
 
git config --global user.email YOUR_EMAIL
 
git config --global user.email YOUR_EMAIL
i.e. git config --global user.email first.last@domain.com
+
i.e. git config --global user.email first.last@domain.com </nowiki>
</nowiki>
 
  
 
OR  
 
OR  
  
  <nowiki>
+
   
git config --user.name YOUR_USERNAME
+
git config --global user.name YOUR_USERNAME
i.e. git config --global user.name CoolGuyBob123
+
i.e. git config --global user.name CoolGuyBob123  
</nowiki>
 
  
  
Line 55: Line 46:
 
To ADD files to 'Staging' prior to committing them to the online repo:
 
To ADD files to 'Staging' prior to committing them to the online repo:
 
  <nowiki>
 
  <nowiki>
git add [FILENAME/DIRECTORY]
+
git add [FILENAME/DIRECTORY] </nowiki>
</nowiki>
 
  
 +
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:
 
And to REMOVE files from 'Staging' so they will NOT be committed:
 
  <nowiki>
 
  <nowiki>
git rm [FILENAME/DIRECTORY]
+
git rm [FILENAME/DIRECTORY] </nowiki>
</nowiki>
 
  
 +
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:
 
To check the status of the files in the repo, compared to those in the online repo:
 
  <nowiki>
 
  <nowiki>
git status
+
git status </nowiki>
</nowiki>
+
 
  
 
=== Committing Files/Directories ===
 
=== Committing Files/Directories ===
 
To add the files from 'Staging' to 'Committed':
 
To add the files from 'Staging' to 'Committed':
 
  <nowiki>
 
  <nowiki>
git commit -m "INSERT COMMENT DESCRIBING THE CHANGES BEING COMMITTED"
+
git commit -m "INSERT COMMENT DESCRIBING THE CHANGES BEING COMMITTED" </nowiki>
</nowiki>
 
  
 
This will add/remove the entire list of staged files/directories to "Committed', along with a comment that will be visible.  
 
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 ===
 
=== Pushing Commits to GitHub ===
 
To push the 'Committed' changes to the online repo, along with their respective comments:
 
To push the 'Committed' changes to the online repo, along with their respective comments:
 
  <nowiki>
 
  <nowiki>
git push
+
git push </nowiki>
</nowiki>
 
  
  
 
=== .gitignore File ===
 
=== .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.
 +
<nowiki>
 +
*.ig would ignore files ending in .ig
 +
backup.* would ignore files starting with backup.*
 +
file1.txt would ignore the specific file, 'file1.txt'  </nowiki>
 +
 +
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.

Latest revision as of 06:34, 3 July 2025

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.