A version control system that manages changes to files.
git clone {https} | Pulls github repository and initializes it. |
git init | Creates .git file to allow for pushing. |
git status | Shows all files that were updated, created, or deleted and if the files are untracked, tracked, or staged. Tracked meaning Git tracks versioning of the file and staged meaning the file is ready to be committed. All staged files are tracked. |
git add {File} | Tells git to track and stage the file so it can be committed. |
git add -A | Tracks and stages all the files and folders listed in status. |
git commit -m ”{Title}” -m ”{Description}” | Commits staged files. It is recommended to have your Title be in the present tense. Ex: “Adds some stuff” |
git reset -hard {commit hash} | Resets to commit specified and deletes any commits after that commit. |
git reset {commit hash} | Resets to commit specified and unstages changes. |
git reset -soft {commit hash} | Resets to commit specified, but leaves files staged. |
git revert {commit hash} | Makes a new commit that undos the changes from the commit hash. Does the opposite of the changes made in that commit hash. |
git log | Lists commit history. This can tell you the commit hashes. |
git log {branch} | Lists commit history for that branch. |
git push {location} {branch} | Pushes commits to the branch at the specified location. |
git remote -v | Shows locations you can push to. |
git remote add {location} {https} | Adds a location you can push to. |
git remote remove {location} | Removes a location you can push to. |
git pull {location} {branch} | Pulls changes made from location’s branch. Pulling is the same as fetching and merging. |
git fetch {location} | The metadata in the local repo is updated, but not files are downloaded. |
git fetch | Fetches all the branches. |
git merge {location}/{branch} | Incorporate the changes from fetch into the specified branch. This downloads the changes from the remote repo. |
git checkout -b {branch} | Creates a new branch. |
git branch | Shows all branches. * is for current branch. |
git checkout {branch} | Switches branch. |
git branch -d {branch} | Deletes branch. |
git stash | Saves changes to a temporary storage area. |
git stash list | Lists all the stashes. |
git stash pop | Restore changes from the stash to your current directory and removes the last stash. |
git stash apply | Restore changes from the stash to your current directory and keeps the last stash. |
git stash drop | Removes the last stash. |
git stash drop {index} | Removes the stash at the index. |
Settings $\rightarrow$ Developer settings $\rightarrow$ Personal access tokens $\rightarrow$ Generate new tokens
git remote set-url {location} https://{username}:{personal access token}@github.com/{owner’s username}/{repository}.git | Gives permissions for the location. |
git rebase {branch} | Takes the commits from current branch and puts them ontop of the specified branch. |
Create a merge commit | Combines the changes from the source branch and the target branch and makes a commit to the target branch with the changes. Preserves the history. |
Squash and merge | Combines all the changes from the source branch and makes a commit to the target branch with the changes. This removes the source branch. Doesn’t preserve the history. |
Rebase and merge | Commits all the previous commits in the source branch and adds them to the target branch. This removes the source branch. Preserves the history. |
<<<<<<< HEAD
// Your changes in the current branch
=======
// Changes from the branch you are merging with
>>>>>>> branch-name
ssh-keygen -t ed25519 -C {github email}
eval "$(ssh-agent -s)"
eval
command evaluates the output of ssh-agent -s
and sets the necessary environment variables in the current shell session. Host *
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519
Host *
means that the variables are being applied to all the hosts.AddKeysToAgent yes
means the private keys will be automatically added to the ssh-agent when you connect to a remote host.IdentifyFile ~/.shh/id_ed25519
sets the default private key for all SSH connections.ssh-add ~/.ssh/id_ed25519
with a new terminal session.ssh -T git@github.com
and you should see Successfully Authenticated
eval "$(ssh-agent -s)"
in order to start the ssh-agent#!/bin/bash
current_branch=$(git symbolic-ref --short HEAD)
while read local_ref local_oid remote_ref remote_oid
do
if [[ "$current_branch" != "main" && "$current_branch" != "master" ]]; then
if [[ $remote_ref =~ master || $remote_ref =~ main ]]; then
read -p "You're about to push to main/master. Are you sure? [y/n] " -n 1 -r < /dev/tty
echo
if [[ $REPLY != "y" || $REPLY != "Y" ]]; then
exit 1
fi
fi
fi
done
exit 0
chmod +x ./.git/hooks/pre-push
A file called .gitignore
which is used to ignore folders or files when pushed to github.
Git ignores use regexes.
This simply doesn’t push the folder called “Folder”, the file called “file”, and any files that start with regex. that are in the Regex folders.
#titles
Folder
file
Regex/regex.*
.env
file and this should always be in the .gitignore
for security reasons.