Skip to content

Git Basic Guide: Master Essential Commands for Beginners

Initial Project

bash
git init
git add .
git commit -m "Initial commit"
git remote add origin <repository-url>
git push -u origin master

Git Configuration

As you read briefly in Getting Started, you can specify Git configuration settings with the git config command. One of the first things you did was set up your name and email address:

bash
git config --global user.name "AvN Learn"
git config --global user.email avnlearn@gmail.com
git config --list --show-origin
git config --global core.editor nvim
git config --global init.defaultBranch main

Now you’ll learn a few of the more interesting options that you can set in this manner to customize your Git usage.

update

bash
git branch -M main

Add remote

bash
git remote add origin git@github.com: avnlearn/manim-recorder.git

Update

bash
git push -u origin main
bash
git push -f origin main

Clone

bash
git pull

Connect SSH

Step - 1 : Generating a new SSH key

You can generate a new SSH key on your local machine. After you generate the key, you can add the public key to your account on GitHub.com to enable authentication for Git operations over SSH.

bash
ssh-keygen -t ed25519 -C "avnlearn@gmail.com"

Step - 2 : Adding your SSH key to the ssh-agent

Before adding a new SSH key to the ssh-agent to manage your keys, you should have checked for existing SSH keys and generated a new SSH key

Step - 2.1 : Start the ssh-agent in the background.

bash
eval "$(ssh-agent -s)"

Depending on your environment, you may need to use a different command. For example, you may need to use root access by running sudo -s -H before starting the ssh-agent, or you may need to use exec ssh-agent bash or exec ssh-agent zsh to run the ssh-agent.

Step - 2.2 : Add your SSH private key to the ssh-agent.

If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.

bash
ssh-add ~/.ssh/id_ed25519

Step - 3 : Adding a new SSH key to your account

You can add an SSH key and use it for authentication, or commit signing, or both. If you want to use the same SSH key for both authentication and signing, you need to upload it twice.

After adding a new SSH authentication key to your account on GitHub.com, you can reconfigure any local repositories to use SSH. For more information, see

Step - 4 : Adding a new SSH key to your account

You can add an SSH key and use it for authentication, or commit signing, or both. If you want to use the same SSH key for both authentication and signing, you need to upload it twice.

After adding a new SSH authentication key to your account on GitHub.com, you can reconfigure any local repositories to use SSH. For more information, see Managing remote repositories.

Note: GitHub improved security by dropping older, insecure key types on March 15, 2022.

As of that date, DSA keys (ssh-dss) are no longer supported. You cannot add new DSA keys to your personal account on GitHub.com.

RSA keys (ssh-rsa) with a valid_after before November 2, 2021 may continue to use any signature algorithm. RSA keys generated after that date must use a SHA-2 signature algorithm. Some older clients may need to be upgraded in order to use SHA-2 signatures.

Step - 4.1 : Copy the SSH public key to your clipboard.

If your SSH public key file has a different name than the example code, modify the filename to match your current setup. When copying your key, don't add any newlines or whitespace.

bash
$ cat ~/.ssh/id_ed25519.pub
# Then select and copy the contents of the id_ed25519.pub file
# displayed in the terminal to your clipboard

Tip: Alternatively, you can locate the hidden .ssh folder, open the file in your favorite text editor, and copy it to your clipboard.

  • In the upper-right corner of any page on GitHub, click your profile photo, then click Settings.
  • In the "Access" section of the sidebar, click SSH and GPG keys.
  • Click New SSH key or Add SSH key.
  • In the "Title" field, add a descriptive label for the new key. For example, if you're using a personal laptop, you might call this key "Personal laptop".
  • Select the type of key, either authentication or signing. For more information about commit signing, see "About commit signature verification."
  • In the "Key" field, paste your public key.
  • Click Add SSH key.

Example (Step)

sh
ssh-keygen -t ed25519 -C "avnlearn@gmail.com"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub

Short Notes

create a new repository on the command line

bash
echo "# avnlearn" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:avnlearn/avnlearn.git
git push -u origin main

push an existing repository from the command line

bash
git remote add origin git@github.com:avnlearn/avnlearn.git
git branch -M main
git push -u origin main

Join the Discussion

Show Comments

No comments

No comments yet.

Post a Comment

Popular Post

25+ Best Devanagari Fonts: Free Unicode & Legacy List

Font formats ​ Most computer fonts used today are in either bitmap or outline data formats. Bitmap fonts : Consist of a matrix of dots or pixels representing the image of each glyph in each face and size. Outline or vector fonts : Use Bézier curves, drawing instructions and mathematical formulae to describe each glyph, which make the character outlines scalable to any size. Outline formats ​ PostScript fonts by Adobe – has various formats, e.g: Printer Font ASCII (PFA) and Printer Font Binary (PFB) TrueType by Apple and Microsoft (file extension: ttf) OpenType by Microsoft, built on TrueType (file extensions: otf, ttf) For most purposes, the technical differences between TrueType and OpenType can be ignored. Other formats ​ The typesetting application TeX and its companion font software, Metafont, traditionally renders characters using its own methods. Some file extensions used for fonts from these two programs are *pk , *gf , mf and vf . Modern versions can also use TrueType and ...
By AvN Learn

AvN Learn English

AvN Learn English

No blogs found in this list.

Share