Handy GIT reference Guide
Setting up git for the first time
yum install git
ssh-keygen -t ed25519 -C "your email address" -f ~/.ssh/project_name
# This is for Mac devices to add the SSH key to the apple keychain
# ssh-add --apple-use-keychain ~/.ssh/project_name
ssh -T git@github.com -i ~/.ssh/project_name
Hi username/project_name! You\'ve successfully authenticated, but GitHub does not provide shell access.
mkdir project_name/
cd project_name/
# This command initialises your directory and creates a .git folder containg your config file
git init
# This updates your config file with your username, but relies on having the "repo2" host configured in your hosts file
git remote add origin git@repo2.github.com:username/project_name.git
# This adds all files and folders to your tree
git add .
# Once your files, you should see that they have been added with a create mode and permissions
git commit -m "Initial Upload"
# Once all files are committed you can run the following command
git push -u origin master
Git Basic commands
git add .
git commit -m "Here is a comment"
git push
Enable Verbose logging
export GIT_TRACE=1
MFA Tokens and Github
I now have MFA enabled so i need to create a personal Access Token which has an expiry date associated to it: https://github.com/settings/tokens
Username: username
Password: use the token generated
delete a git branch
git checkout master
git branch -d <branch name>
git push origin --delete <branch name>
# This command deletes any branches that don't exist on the remote side
git checkout master
git fetch -p
merging a new git branch
## create a new branch and checkout
git checkout -b new-branch
touch NEWFILE
git add .
git commit -m "added NEWFILE"
git push --set-upstream origin new-branch
## checkout to master, merge and delete branch
git checkout master
git merge new-branch -m "merging new branch"
git branch -d new-branch
git push origin --delete new-branch
add new remote repository to YOUR repository
This updates the .git/config file
git remote add <repo-alias> https://git-codecommit.eu-west-2.amazonaws.com/v1/repos/testing
git remote remove <repo-alias>
Set Global Settings
git config --global user.name "username"
git config --global user.email "email@address.co.uk"
git config --global gpg.program gpg
Set Local Settings
Local settings are per repo, whereas the global settings are for all repos.
git config --local -l
git config --local user.signingkey <-- signing key -->
Confirm your SSH key
This is useful if you have created an SSH key but you aren’t sure whether it is the right one within your github account
ssh-keygen -lf key.pub
Git commit with signing enabled
Ensure you have a GPG cert and that you have added it to your github configuration. Ensure the gpg program has been configured globally and that you have either set the –local or –global user.signingkey setting.
git commit -a -S -m "adding update to README"