Quick Github Tutorial For Beginners

This is not meant to be an exhaustive tutorial. This does not discuss the concepts of Git that you should know (like working directory, staging area, head). This is a very quick demonstration of how to get started.

Quick Github Tutorial Or How To use Git in Linux

git config --global user.name "amirootyet"  
git config --global user.email "amiroot...@gmail.com"  
git config --global credential.helper cache

If you use a Proxy Server to connect to the Internet:

git config --global http.proxy http://user:pass@proxyserver:port

After you’ve configured the git global settings, you can check them:

git config --list  

git init  
git add .  #to add all files


git add <filename> #to add a particular file


git add '*.<fileextension>' # to add all files of a specific type

git commit -m "Initial Commit"
git status

Now, we need to push these changes to the remote location:

git push origin main

Enable SSH Keys for both Personal and Work accounts on Macbook

cat ~/.ssh/config

Config should contain the following. If not, add it in:

Host *
AddKeysToAgent yes
UseKeyChain yes
IdentityFile ~/.ssh/id_rsa
ForwardAgent yes

Generate SSH public-private keypairs to work on git repos as discussed here.

ssh-keygen -t rsa -b 4096 -C "username1@gmail.com"

Save public-private keys as github-<username>. Set a passphrase that will be used to access the private key.

Register your keys on Github as discussed here. If your organization has SAML SSO, enable SSO on the SSH key as shown here.

vi ~/.ssh/config

Append the following:

#work account
Host github.com-username1
HostName github.com
User git
IdentityFile ~/.ssh/github-username1
IdentitiesOnly yes

#personal account
Host github.com-username2
HostName github.com
User git
IdentityFile ~/.ssh/github-username2
IdentitiesOnly yes

Git clone the remote repo:

git clone git@github.com-username1:username1/reponame.git

If the repo already exists on local, navigate to the directory and check git config:

git config --local -e

Add or append the following:

name = username1
email = username1@gmail.com

Also check the remote URL is in the correct format:


Your local git config file should now look something like this:

General helpful Git commands

To uncommit changes before pushing to remote:

git reset HEAD~1

To create a new branch, checkout to it, add and push content:

git checkout -b "<branchname>"
git add .
git commit -m "<message>"
git push -u origin <branchname>

On MacOS, to remove the .DS_Store files:

find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch

Also, add the .DS_Store in the .gitignore file at the repo’s root.

When git pull fails because “error: Your local changes to the following files would be overwritten by merge:”, you have an option to discard all local changes (careful!) or to a specific file:

git reset --hard  ## discard all changes
git checkout filename ## discard changes to a specific file
Pranshu Bajpai
Pranshu Bajpai
Principal Security Architect

Pranshu Bajpai, PhD, is a principle security architect..