INFO L1 Git Lecture
INFO L1 Git Lecture
KIMBI Xaveria
COURSE OBJECTIVES
4
Why Use a Version
Control System?
Change History: You can see who
changed what and when.
Reverting Changes: If an error is
introduced, it's easy to go back to a
previous version.
Collaboration: Multiple people can work
on the same project without overwriting
each other's work.
4
History of Git
4
Differences Between Git and Other
Version Control Systems
Centralized vs. Distributed: Unlike
systems like SVN, which have a
central repository, Git allows each
developer to have a complete copy of
the repository.
Performance: Git is optimized to
handle large projects with thousands
of files.
4
Installing Git
Installation on Windows, macOS, and Linux
Windows: Download the installer from
git-scm.com and follow the
instructions.
macOS: Use Homebrew with the
command brew install git.
Linux: Use your distribution's package
manager, e.g., sudo apt install git for
Ubuntu. 4
Initial Configuration
After installation,
configure your username and email:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
4
Basic Git Commands
To create a new Git
Initializing a New
repository, use:
Repository
git init repository-name
To copy an existing
Cloning an Existing repository, use:
Repository git clone https://repository-
url.git
4
Basic Git Commands
To add files to the index:
Adding Files to git add filename
the Index To add all files: git add .
4
Basic Git Commands
Checking the To see modified files and those
Status of the waiting to be added:
Repository git status
SWITCH
4
Branching in Git
A branch is a parallel version of
What is a the code. It allows you to work on
Branch? features or fixes without
affecting the main branch.
List branches: git branch
Create a new branch: git branch branch-
Commands for
Working with name
Branches Switch branches: git checkout branch-
name
Merge branches: git merge branch-name 4
Collaborating with Git
Remote repositories allow you to
Using Remote share your code with other
Repositories developers.
4
Collaborating with Git
Fetching Changes To fetch the latest changes:
from a Remote git pull origin branch-name
Repository
4
Adding the Public Key to
GitHub
Steps to Add the Public Key
Copy the public key to the clipboard:
cat ~/.ssh/id_rsa.pub
Or, if you used a different name:
cat ~/.ssh/id_paul.pub
Log in to your GitHub account.
Go to Settings > SSH and GPG keys > New SSH key.
Paste the public key in the provided field and give it a title.
4
Click Add SSH key.
Configuring Multiple Git
Accounts on the Same Machine
Modifying the config File
To use multiple SSH keys on the same machine, you must modify the config file in the
~/.ssh/ directory.
1. Open or create the config file: nano ~/.ssh/config
2. Add the following configurations:
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Host paul
HostName github.com
User git
4
IdentityFile ~/.ssh/id_paul
Using the paul Alias
When configuring an alias for a repository, you must use
4
Testing the SSH Connection
is successful.
4
Best Practices with SSH and Git
layer of security.
multiple accounts.
4
The end !