git a Clue with Revision Control
Revision Control
Remember folks, I might be able to provide a shortcut to using git revision control, but nothing beats Reading The Forgotten Manual
Overview
One of the most underrated and underrepresented task in all the cyber spaces is version control/source controls. This is the practice of managing and tracking changes to your data, namely software code. A well known, popular and effective Version Control System (VCS) is something called git. A simple, easy 3 letter word that's fun to say! This is not to be confused with GitHub or GitLab, they are not exactly the same thing. GitHub, and GitLab are remote repositories (repo) and collaborative spaces built on git VCS.
Preparations
To Start we will generate a key-pair for our remote git repo to securely upload and track our files.
In the terminal of your developer system, lets first generate an SSH key for your remote repository.
# Generate a SSH Key for our remote repository.
ssh-keygen -t rsa -C "YourCoolEmail@SomeEmailDomain.TLD"
# or
ssh-keygen -t rsa -C "YourCoolGitUsername"
# Enter a passphrase or leave it blank.
# Enter path and file name i.e ~/.ssh/rsa_GitHub
# Adjust your ssh keys and directory.
# Set ownership
sudo chown -R $USER:$USER ~/.ssh
# Set directory and file permissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_rsa # Private key
chmod 644 ~/.ssh/id_rsa.pub # Public key
chmod 600 ~/.ssh/authorized_keys # If present locally
chmod 644 ~/.ssh/config # Optional, if using SSH config
# Print the PUBLIC key
cat ~/.ssh/rsa_GitHub.pubNext, we will need a remote git repo. Open your default browser and log into or create yourself an account in GitHub, GitLab or any other remote hosted repository.
Import your ssh PUBLIC key into the remote repository account we created. Create a new empty repository
Testing SSH to Git Repo
# Point to your ssh key we generated.
# Usful for when you have multiple ssh keys.
# -c to set a configuration setting
#core.sshCommand is used to set the i flag in the SSH command.
# This allows the use of a specific identity file
git clone -c "core.sshCommand=ssh -i ~/.ssh/some-GIT-SSH-key"
# Test ssh key
ssh -v -T git@github.com
Configure your Local Git
When executing a clone, or push via ssh you will be prompted to enter a username and maybe a password. This will update the global config but we can adjust or pre-configure with the following
# Add your username
git config --global user.name "YourUserName"
# Email will be public if used. Be sure to adjust GitHub config or remove if not needed.
git config --global user.email "YourCoolEmail@SomeEmailDomain.TLD"
# If you need to remove or change your email
git configset --global --unset user.email
# If you need to remove onamenamenamenamer change your user name.
git config --global --unset user.name
# To Review the current config.
git config --list
Using Git
# Always read the fine manuals!
git help <verb>
git <verb> --help
git <verb> -h
man git-<verb>
# Create and initialize your repo
mkdir some-project-folder
cd some-prject-folder
# create a new subdirectory named .git that acts as the repository skeleton.
git init #
# To start version-congrolling existing files
git add . # all changes
git add ./file.sh # add a specific file
git add *.c # add all files with a dot C extention.
git add ./SomeDir/ # add a directory
# Commit your changes and comment
git commit -m "Some Change"
# sync your changes to your repo branch named "master"
git push origin master
# Clone an existing repository
git clone https://github.com/some/repo.git
# Clone an existing repository but with a new directory name
git clone https://github.com/some/repo.git repodir
# create a git branch of a sub directory in a main repo
# --prefix= is used to know what directory
# and the orignin public is the branch name.
git subtree push --prefix=public origin public
git pull # update your current repo
References
Last updated