Work With Github

This is a walkthroug. You are going to create a local repository, and do everything needed to push your work to a remote github repository.

Create a local repository

  • Create your local repository by typing:
1git init
  • Config git user name and email (these are not github user and email):
1git config --local user.name "Yuval Teacher"
2git config --local user.email yuvalaws1@gmail.com
  • Create a file, add it to the staging area, then commit.

Add a remote repository

  • Go to GitHub and create a new repository.
    (In my example I have created one called gittest)
  • Go to the green <>Code button dropdown, and make sure that you select SSH prior to copying the remote address.
    Copy the address (it should begin and end with the word git)
  • Then type the command to create a remote definition in your local git repository:
1git remote add githubrem git@github.com:yuvalaws1/gittest.git

(I use githubrem as my name for a remote, you can choose another name)

  • Verify the remote you have created:
1git remote -v

Add SSH key

  • You have to make sure you are authenticated by GitHib using SSH.
  • We start by creating a pair of keys, as in the following example:
1ssh-keygen -t ed25519 -C "yuvalaws1@gmail.com"
  • The email address at the end is just a comment you attach to the public key.
  • The response:
1Generating public/private ed25519 key pair.
  • Now I can change the key name:
1Enter file in which to save the key (/home/yuval/.ssh/id_ed25519): /home/yuval/.ssh/yuvalaws1_all
  • I left everything else empty
  • To verify:
1**ls ~/.ssh**

Add keys to the ssh agent

You can read about the ssh agent here.

1eval "$(ssh-agent -s)"
2ssh-add ~/.ssh/yuvalaws1_all

Add the public key to github

Add the public key to github like this:

  • Cat the public key:
1cat ~/.ssh/yuvalaws1.pub
  • Copy with your mouse
  • Go to your account settings (top-right-settings)
  • Click SSH and GPG keys.
  • Click New SSH key.
  • In the "Title" field, add a descriptive label for the new key.
  • Select the type of key (authentication in out case)
  • In the "Key" field, paste your public key (including the email part)
  • Click Add SSH key.

Push your changes

  • Push you changes (you are in a branch called master and we are setting the remote branch that we are pushing the changes into):
1git push --set-upstream githubrem master
  • Refresh the github view to see the changes