Skip to content

Instantly share code, notes, and snippets.

@John-Almardeny
Last active January 27, 2018 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save John-Almardeny/e409174137f69669843a2d001e7066da to your computer and use it in GitHub Desktop.
Save John-Almardeny/e409174137f69669843a2d001e7066da to your computer and use it in GitHub Desktop.
Easy Github Setup from scratch on Ubuntu for first time
#!/bin/bash
#https://gist.github.com/John-Almardeny/e409174137f69669843a2d001e7066da
#Set up Github from scratch on Ubuntu for first time
# if Git is not installed -> go head and install it
if [ ! $(which git) ];then
echo -e "\n*****************************************"
echo "git not found, starting to install it..."
echo -e "*****************************************\n"
sudo apt-get install git
echo -e "\n****Git is now installed on your machine****\n\n"
fi
#Set up the minimum Git Global Settings
echo "Setting Git Global Settings"
echo "Enter your full name: "
read name
echo "Enter your valid email: "
read email
echo "Enter the name of your preferable editor: "
read editor
git config --global user.name "$name"
git config --global user.email "$email"
git config --global core.editor "$editor"
echo -e "\n****Git Global Settings Added Successfully****"
echo $(git config --global -l)
echo -e "\n\n"
cd ~
#replace all spaces with underscroll
name=${name// /_}
#Generate SSH Key
yes "" | ssh-keygen -f ~/.ssh/github_$name
echo -e "\n****Github Key Generated and Added Successfully****"
key=$(cat ~/.ssh/github_$name.pub)
echo -e "\n\n"
#First check if curl is installed
# if not -> intstall it
if [ ! $(which curl) ];then
echo -e "\n*****************************************"
echo "curl not found, starting to install it..."
echo -e "*****************************************\n"
sudo apt-get install curl
echo -e "\n****Curl is now installed on your machine****\n\n"
fi
#Adding the key to github account
echo "-------------------------------------"
echo "Adding the key to your Github account"
echo "Enter your Github Username: "
read user
echo "Enter a name for this key: "
read key_name
key_name=${key_name// /_}
response="$(curl -u $user --data "{\"title\":\"$key_name\",\"key\":\"$key\"}" https://api.github.com/user/keys)"
if [[ $response = *"Bad credentials"* ]]; then
echo -e "\nIncorrect Username or/and Password!\n"
exit 0
fi
echo -e "\n All are now set and done for you ... cheers :)\n"
@John-Almardeny
Copy link
Author

John-Almardeny commented Jan 27, 2018

What Does This File Do For Me?

  1. Installing Git.
  2. Setting up Git Minimum Global Settings.
  3. Generating and Adding SSH Key.
  4. Adding the Generated SSH Key to your GitHub Account.

How To Use?

  1. Open the Terminal and change to the current directory that git_setup.sh exists in:
    cd /path_to_git_setup.sh_file

  2. In order to make the file executable, Issue this command :
    sudo chmod +x git_setup.sh

  3. For the very first time, create a github directory, you will save all your repos in it from now then.

cd ~
mkdir github
cd github
  1. Move the git_setup.sh to your github directory to ease the work:
    mv /path_to_git_setup.sh_file .
    don't forget the dot (.) above, it means "to the current directory as destination"

  2. Run the file like this: ./git_setup.sh and Follow the Instructions.

Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment