What is github ?
GitHub is a platform that hosts code, providing version control and collaboration features. It enables you and others to work together on projects from anywhere in the world.
What is git ?
Git is a free and open-source distributed version control system. It’s designed to handle everything from small to very large projects with speed and efficiency
Definition of terms
Branch - A version of the codebase that diverges from the main branch to isolate changes for specific features, fixes, or experiments.
Commit - A snapshot of your changes, saved to your local repository. Each commit is uniquely identified by a checksum.
Stage - The area where Git tracks changes that are ready to be included in the next commit. Files in the staging area are prepared (staged) for the next commit.
Merge - The process of integrating changes from one branch into another, typically the main branch.
Pull Request - A proposal to merge changes from one branch into another, often used in collaborative environments to review and discuss changes before they are merged.
Fork - A personal copy of someone else's project that lives on your GitHub account.
Remote - A common repository that all team members use to exchange their changes.
Origin: The default name Git gives to the server from which you cloned.
Master: he default branch name given to a repository when it is created. In modern practice, it is often replaced with main
Repository: A storage location where your project lives, containing all the files and revision history.
Checkout: The action of switching from one branch to another or to a specific commit.
Push: The action of sending your commits to a remote repository.
Pull: The action of fetching changes from a remote repository and merging them into your current branch.
Fetch: The action of retrieving updates from a remote repository without merging them into your current branch.
Common task perform with Git
Create a repository
Create a branch
Make changes to a file
Stage changes
Commit changes
Push changes to a remote repository
Merge changes
Delete a branch
Install Git
Download Git from the official website: https://git-scm.com/downloads
Create a github Account
https://github.com/
Generate new SSH Key
Open Git Bash
Generate SSH Key
ssh-keygen -t ed25519 -C "your_email@example.com"
This creates a new SSH key, using the provided email as a label.
> Generating public/private ALGORITHM key pair.
When you're prompted to "Enter a file in which to save the key", you can press Enter to accept the default file location. Please note that if you created SSH keys previously, ssh-keygen may ask you to rewrite another key, in which case we recommend creating a custom-named SSH key. To do so, type the default file location and replace id_ALGORITHM with your custom key name.
> Enter file in which to save the key (/c/Users/YOU/.ssh/id_ALGORITHM):[Press enter]
Adding a new SSH key ot your GitHub account
$ cat ~/.ssh/id_ed25519.pub
copy the public key .
In the upper-right corner of any page on GitHub, click your profile photo, then click Settings.
In the "Access" section of the sidebar, click SSH and GPG keys.
Click New SSH key or Add SSH key.
In the "Title" field, add a descriptive label for the new key. For example, if you're using a personal laptop, you might call this key "Personal laptop".
In the "Key" field, paste your public key.
Click Add SSH key.
Testing your SSH connection
Open Git Bash.
Enter the following:
ssh -T git@github.com
# Attempts to ssh to GitHub
Verify that the fingerprint in the message you see matches GitHub's public key fingerprint. If it does, then type yes:
> Hi USERNAME! You've successfully authenticated, but GitHub does not
> provide shell access.
Verify that the resulting message contains your username
Configuring git for the first time use
setting your identity
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
Creating New Repository
Access your github account by logging in to github.com
In the upper-right corner of any page, select +, then click New repository.
Type a name for your repository, and an optional description.
Select Public of Private type
Click Create Repository Button
After creating the repository there are two options available just select which is appropriate for your needs
New Repository
echo "# utas-workshop-testing" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:<USERNAME>/<Repository-Name>.git
git push -u origin main
Existing Repository
git remote add origin git@github.com:<USERNAME>/<Repository-Name>.git
git branch -M main
git push -u origin main
Cloning an Existing Repository
To copy an existing Git repository the command git clone can be used
example:
$ git clone https://github.com/piperhuntress/postIT-app
This will copy this repository to your local computer with the folder named libgit2
if you want to specify your own folder name you can use the command:
$ git clone https://github.com/piperhuntress/postIT-app myownfoldername
Untracking Files
intentionally untracked files that Git should ignore.
cd into your folder and create a .gitignore file, or you can copy the .gitignore file located inside your client or server folder respectively and paste it in the root folder
example:
/mern-project
├── .gitignore <-- Place the .gitignore file here
├── client/
├── server/
open the .gitignore file and update the following content
/node_modules --> node_modules/
**/node_modules/
this tells Git to ignore all node_modules directory including subdirectory
the Two consecutive asterisks ( ** ) in patterns matched against full pathname, meaning a leading " * * " followed by a slash means match in all directories
read more about gitignore . . . .
Stagging, Commit, Push, Pull, Status
Stagging
$ git add .
Check Status
$ git status
status will display to let us know if our files are stagged or unstagged, Status will also inform us if our repository is up to date, behind or ahead of the remote repository. to get the latest status of our repository we need to issue the command
$ git fetch
This will fetch any updates from the remote repository allowing us to know the current updates between our remote repository and local repository.
Commit
$ git commit -m 'your message'
Push
$ git push -u origin <branch>
Pull
$ git pull
The git pull command will download all files that are newly updated from our remote repository to enable our remote and local repository to be sync with each other.
Branching
Creating a new branch
$ git branch testing
Listing Branches
$ git branch
Switching Branches
$ git checkout testing