This article will tell you how to install and config git.

1.Install Git

For the latest stable version for your release of Debian/Ubuntu.

1
$ apt-get install git -y

If it is installed successfully ,you use command git --version and you will see the version.

2.First-Time Git Setup

2.1 Set your identity

If you pass the –global option ,you need to do this only once because then Git will always use that information for anything you do on that system.
If you want to override this with a different name or email address for specific projects, you can run the command without the –global option when you’re in that project.

1
2
$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]

2.2 Set your editor

Now you can configure the default text editor that will be used when Git needs you to type in a message.
If not configured, Git uses your system’s default editor.
If you want to use a different text editor, such as Emacs, you can do the following:

1
$ git config --global core.editor emacs

2.3 Checking Your Settings

If you want to check your configuration settings, you can use the git config –list command to list all the settings Git can find at that point:

1
2
3
4
$ git config --list
user.name=John Doe
[email protected]
...

You can also check what Git thinks a specific key’s value is by typing git config :

1
2
$ git config user.name
John Doe

3.Connecting to GitHub with SSH

3.1 About SSH

Using the SSH protocol, you can connect and authenticate to remote servers and services. With SSH keys, you can connect to GitHub without supplying your username or password at each visit.

3.2 Checking for existing SSH keys

By default, the filenames of the public keys are one of the following:

  • id_dsa.pub
  • id_ecdsa.pub
  • id_ed25519.pub
  • id_rsa.pub
1
2
$ ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist

3.3 Generating a new SSH key

Open Terminal ,and paste the text below, substituting in your GitHub email address.

1
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"

3.4 Adding a new SSH key to your GitHub account

① Copy the SSH key to your clipboard

Your ssh file is saved as ~/.ssh/filename.pub ,such as id_rsa.pub.
You can open your ssh file ,and copy the text to your clipboard.

② Adding the SSH key to your GitHub account

In the “Title” field, add a descriptive label for the new key.
Paste your key into the “Key” field.

3.5 Testing your SSH connection

Open Terminal ,and paste the text below.

1
$ ssh -T [email protected]

If your SSH connection is ok ,you will see a message like this:

1
2
Hi username! You've successfully authenticated, but GitHub does not
provide shell access.

4.Reference

Connecting to GitHub with SSH
Git - Book