Difference between revisions of "Git Fundamentals"
(Initial page creation) |
|||
| Line 1: | Line 1: | ||
| − | This | + | === 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 ==== | ||
| + | <nowiki> | ||
| + | sudo dnf install git | ||
| + | </nowiki> | ||
| + | |||
| + | ==== Ubuntu/Debian ==== | ||
| + | <nowiki> | ||
| + | sudo apt-get install git | ||
| + | </nowiki> | ||
| + | |||
| + | |||
| + | === Creating a Repo === | ||
| + | Once Git is installed, use the command below to begin with creating a repository: | ||
| + | |||
| + | <nowiki> | ||
| + | gh repo create | ||
| + | </nowiki> | ||
| + | |||
| + | 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:; | ||
| + | |||
| + | <nowiki> | ||
| + | git init | ||
| + | </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: | ||
| + | |||
| + | <nowiki> | ||
| + | git config --global user.email YOUR_EMAIL | ||
| + | i.e. git config --global user.email first.last@domain.com | ||
| + | </nowiki> | ||
| + | |||
| + | OR | ||
| + | |||
| + | <nowiki> | ||
| + | git config --user.name YOUR_USERNAME | ||
| + | i.e. git config --global user.name CoolGuyBob123 | ||
| + | </nowiki> | ||
| + | |||
| + | |||
| + | === Adding Files/Directories to Staging === | ||
| + | To ADD files to 'Staging' prior to committing them to the online repo: | ||
| + | <nowiki> | ||
| + | git add [FILENAME/DIRECTORY] | ||
| + | </nowiki> | ||
| + | |||
| + | And to REMOVE files from 'Staging' so they will NOT be committed: | ||
| + | <nowiki> | ||
| + | git rm [FILENAME/DIRECTORY] | ||
| + | </nowiki> | ||
| + | |||
| + | To check the status of the files in the repo, compared to those in the online repo: | ||
| + | <nowiki> | ||
| + | git status | ||
| + | </nowiki> | ||
| + | |||
| + | === Committing Files/Directories === | ||
| + | To add the files from 'Staging' to 'Committed': | ||
| + | <nowiki> | ||
| + | git commit -m "INSERT COMMENT DESCRIBING THE CHANGES BEING COMMITTED" | ||
| + | </nowiki> | ||
| + | |||
| + | 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: | ||
| + | <nowiki> | ||
| + | git push | ||
| + | </nowiki> | ||
| + | |||
| + | |||
| + | === .gitignore File === | ||
Revision as of 06:10, 30 May 2024
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]
And to REMOVE files from 'Staging' so they will NOT be committed:
git rm [FILENAME/DIRECTORY]
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