Git Basics for Every Developer
This lesson provides a crash course on Git, a fundamental version control system for developers, and Github, the home for your Git repositories.
This lesson equips you with basic Git commands frequently used by developers. Think of it as a cheat sheet, and we will build on it throughout the course. Here’s all commands mentioned in the video:
Checking Git Installation:
- git --version- This command verifies if Git is already installed on your system and displays the version.
Git User Setup:
- git config --global user.name "John Doe"- Sets your Git username for global use.
- git config --global user.email "john@test.com"- Sets your Git email address for global use.
Initializing a Git Repository:
- git init -b main(in your project's root directory) - Initializes a new Git repository in your project directory and creates a new "main" branch.
Adding and Committing Changes:
- git add .- Adds all modified files in your project to the staging area.
- git commit -m "init"- Creates a commit with a descriptive message ("init" in this example).
Connecting to a Remote Repository:
- git remote add origin <URL>(replace- <URL>with the repo’s SSH URL) - Adds the remote GitHub repository as "origin" for future operations.
- git push -u origin main- Pushes the initial commit ("init") to the remote "main" branch on GitHub.
Subsequent Updates:
After making changes to your local repository, use these commands to keep your remote repository updated:
- git add -A- Adds all modified files to the staging area.
- git commit -m "message"- Creates a commit with a descriptive message.
- git push origin main- Pushes your local commits to the remote "main" branch on GitHub.
Generating SSH Key:
- ls -al ~/.ssh- Checks if you have an existing SSH key on your machine.
- ssh-keygen -t ed25519 -C "youremail@example.com"- Generates an SSH key for secure communication with GitHub.
- pbcopy < filename(replace "filename" with your key's actual path and name) - Copies the generated SSH key to your clipboard.
Generating SSH Key (Windows):
- Get-ChildItem -Path $env:USERPROFILE.ssh - Checks if you have an existing SSH key on your machine.
- ssh-keygen -t ed25519 -C "youremail@example.com" - Generates an SSH key for secure communication with GitHub.
- Get-Content C:\Users\enterusernameHere.ssh/id_ed25519.pub | Set-Clipboard
