First thing first. Create an account and log in to GitHub [Link].

Enter Settings > SSH and GPG Keys > Add SSH Key.

Give a meaningful name and paste your SSH Public Key.

Create a New Repository. It can be public or private.

It is always good to Add a README.md file.

Add description and instructions about this repo in the README.md file and Save.

Then click on DOWNLOAD CODE, select SSH, and copy the URL:

On your Linux terminal, where you have the Private Key that matches with the uploaded Public Key issue the command to download the repository.

git clone [email protected]:user/private.git

Pulling changes from remote to local:

git pull
git pull --verbose

It is important to give Git your identification in order to be able to make changes on your repositories:

git config --global user.email "Your E-Mail"
git config --global user.name "Your Name"
cat ~/.gitconfig

Modify the text in the README.md file that you pulled from the repository and Save.

Check the status of the online repository against the local pulled repository:

git status

Output:

...
modified: README.md
...

Check what is different by issuing:

git diff
git diff --staged
git diff --staged README.md
git diff --cached README.md 
git diff file1.txt file2.txt
git diff COMMIT1-ID COMMIT2-ID
git --no-pager diff COMMIT1-ID COMMIT2-ID

Commit and push the modification to the online repository:

git add README.md
git commit -m "message about the update"
git commit --amend -m "Updating message for the previous commit"
git add anotherFile.txt
git commit --amend --no-edit
git push

Remove one file or all files from the stage:

git reset README.md
git reset

Check if the updates were done on GitHub.

To create a repository locally first create a folder and change into it:

git init
git remote add origin [email protected]:user/private2.git
git remote -v
git push -u origin master
git push -u origin branchName

Check what branch you are in:

git branch

List all branches including remote ones:

git branch -a

Create a branch.

git branch firstBranch

Create a branch and switch to it:

git checkout -b firstBranch

To make the first push to the new branch issue:

git push --set-upstream origin firstBranch

Note: –set-upstream is the same as -u used previously.

Eventually, to delete the beach locally (safe way):

git branch -d firstBranch

Forcing delete a local branch losing all changes of the branch:

git branch -D frstBranch

Pushing the branch deletion to remote:

git push origin --delete firstBranch

Show the differences between the current branch to another.

git diff firstBranch

Then merge the branch final version to the master:

git merge firstBranch

Switch to another branch.

git checkout master

Renaming or moving files:

git mv fileName.txt fileNewName.txt
git mv dir1/fileName dir2/

To list all of the commits:

git log
git log -p
git log --all --graph --oneline --decorate

View one specific commit:

git show b82ed4bb1a7dbe3ce291af17e73721dbe0c40011
git show b82ed4

Discard not committed changes to a file:

git checkout -- fileName

Revert last changes (creates a new commit to invert changes):

git revert HEAD

Undo last changes:

git reset HEAD

To revert the changes of a specific commit:

git reset 79645cdce5ef42595fee98306b9644c93f098e55

Or

git reset --hard 79645cdce5ef42595fee98306b9644c93f098e55

Put all your changes aside to work on another issue in the original code:

git stash

List all code changes you have stashed:

git stash list

Show what is in the stash:

git stash show

To get back the changes put aside:

git stash apply

Search for string through all history of commits:

git log -S 'text' --source --all

Searching with regular expression:

git log -G "regex expression" --source --all

BONUS

Use Sandfly’s SSH Hunter for auditing SSH keys. Unfortunately it is not open source but this agent-less tool might give precious information to visualise what are the keys present in the system and how they are being used (or misused), orphan, or unauthorised keys [Link].

Create your own Private Git Server [Link].