Git Setup

GIT Tutorials


Configure Git before you create commits or connect to a remote repository. A good setup records the correct author, uses a predictable initial branch, and gives you a secure authentication method.

Configure Your Git Identity

Git stores an author name and email address in every new commit. Set them for your user account:

# Set the name stored in new commits
git config --global user.name "Priya Shah"

# Set the email stored in new commits
git config --global user.email "[email protected]"

Confirm the effective values and see which configuration file provides each one:

git config --list --show-origin

Example output:

file:C:/Users/Priya/.gitconfig user.name=Priya Shah
file:C:/Users/Priya/.gitconfig [email protected]

If one repository needs another identity, enter that repository and repeat the commands without --global.

Set the Default Initial Branch

Git 2.x may still create master unless you configure another name. Use main for newly initialized repositories:

git config --global init.defaultBranch main

This setting does not rename branches in existing repositories.

Choose a Text Editor

Git opens an editor for commit messages and interactive operations. For Visual Studio Code, run:

git config --global core.editor "code --wait"

For Nano, run:

git config --global core.editor nano

Choose an editor that is installed and available from your terminal.

Choose HTTPS or SSH Authentication

Git itself does not host repositories. Services such as GitHub, GitLab, and Bitbucket accept HTTPS or SSH connections. HTTPS usually uses a credential manager or token. SSH uses a key pair and is convenient for regular command-line work.

Security tip: Never copy your private SSH key into a website or send it to another person. Upload only the public key whose filename ends in .pub.

Generate an Ed25519 SSH Key

First, check whether your ~/.ssh directory already contains keys:

ls -al ~/.ssh

Create an Ed25519 key when you need a new one:

# Use the email address associated with your hosting account
ssh-keygen -t ed25519 -C "[email protected]"

Example prompt:

Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/priya/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):

Press Enter to accept the default path, then enter a strong passphrase. On legacy systems without Ed25519 support, use ssh-keygen -t rsa -b 4096.

Add the Key to the SSH Agent

On Git Bash, Linux, or most Unix shells, start the agent and add the private key:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Example output:

Agent pid 59566
Identity added: /home/priya/.ssh/id_ed25519 ([email protected])

Windows PowerShell and macOS can use operating-system-specific agent commands. Follow your hosting provider's current instructions for your platform.

Copy the Public Key

Display the public key, then copy the entire line:

cat ~/.ssh/id_ed25519.pub

Add it to the SSH-key settings of your Git hosting account. Keep the private file ~/.ssh/id_ed25519 on your computer.

Test a GitHub SSH Connection

ssh -T [email protected]

The first connection may ask you to verify GitHub's host fingerprint. Compare it with the fingerprint published by GitHub before accepting it.

Successful authentication:

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

The command normally exits with status 1 because GitHub provides Git access, not an interactive shell. The authentication message confirms that the key works.

Create a New Repository

Create a project directory and initialize it with main as the first branch:

mkdir weather-dashboard
cd weather-dashboard
git init -b main

Example output:

Initialized empty Git repository in /home/priya/weather-dashboard/.git/

Clone an Existing Repository

Use an HTTPS URL when you use a credential manager:

git clone https://github.com/example/weather-dashboard.git

Use an SSH URL after your SSH key works:

git clone [email protected]:example/weather-dashboard.git

Example output:

Cloning into 'weather-dashboard'...
remote: Enumerating objects: 42, done.
Receiving objects: 100% (42/42), done.

Check the Final Configuration

git config --global user.name
git config --global user.email
git config --global init.defaultBranch

Example output:

Priya Shah
[email protected]
main

Conclusion

A reliable Git setup starts with the correct commit identity and initial branch. Choose HTTPS or SSH for remote access, protect private keys, and verify each setting before you begin project work.



Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram