0% found this document useful (0 votes)
24 views25 pages

INFO L1 Git Lecture

Uploaded by

ebederoy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views25 pages

INFO L1 Git Lecture

Uploaded by

ebederoy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Course Lecturer:...........................................................................Dr.

KIMBI Xaveria
COURSE OBJECTIVES

Understand the basic concepts of version


control with Git.
Learn to use Git for tracking file changes.
Know how to collaborate effectively with
other developers.
Understand the importance of SSH for
secure connections to Git.
Learn to generate SSH keys and configure
them for Git.
Set up multiple Git accounts on the same
machine.
2
INTRODUCTION TO VERSION
CONTROL

Version control is a system


What is that records changes to
Version files or a set of files over
time. It allows you to revert
Control? to previous versions, track
the history of changes, and
collaborate with others.

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

Git was created by Linus Torvalds


in 2005 for the development of the
Linux kernel. It was designed to be fast,
distributed, and efficient.

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 .

To save changes to the


Committing history: git commit -m
Changes "Commit message"

4
Basic Git Commands
Checking the To see modified files and those
Status of the waiting to be added:
Repository git status

SWITCH

To display the commit


Viewing Commit history:
History git log

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.

Pushing Changes To send your commits to a remote


to a Remote
repository: git push origin branch-name
Repository

4
Collaborating with Git
Fetching Changes To fetch the latest changes:
from a Remote git pull origin branch-name
Repository

When merging branches, conflicts may


arise. Git will indicate which files are in
Resolving conflict, and you will need to resolve
Conflicts them manually before committing the
changes.
4
Introduction to SSH
What is SSH?
SSH (Secure Shell) is a secure
communication protocol that allows
access to remote machines and
transfers data securely. In the context
of Git, SSH is used to authenticate and
secure connections to remote
repositories. 4
Introduction to SSH
Why Use SSH with Git?
Security: SSH keys provide a more
secure authentication method than
passwords.
Convenience: Once set up, SSH
connections do not require password
entry.
4
Generating an SSH Key
Open your terminal.
Execute the following command:ssh
keygen -t rsa -b 4096 -C
"your_email@example.com"
Replace your_email@example.com with the
email address associated with your GitHub
account.
4
Generating an SSH Key
Specify the file name:
When prompted to specify the file name, press Enter to
accept the default name (~/.ssh/id_rsa) or enter a different
name (e.g., ~/.ssh/id_paul).
Enter a passphrase:
You will be prompted to enter a passphrase. You can choose
to set one for added security or leave it empty.
Key generated:
The key will be generated, and you will see a message
indicating where it has been saved. 4
Adding the SSH Key to
the SSH Agent
After generating the key, you need to add it to
the SSH agent: ssh-add ~/.ssh/id_rsa
Or, if you used a different name: ssh-add
~/.ssh/id_paul

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

this alias when setting up your Git repository. For

example, to change the URL of your repository to use paul:

git remote set-url origin paul:Paul/BankApp-Gen.git

4
Testing the SSH Connection

To ensure everything is working correctly, test the

connection to GitHub: ssh -T powerksoft

You should receive a welcome message if the connection

is successful.

4
Best Practices with SSH and Git

Use passphrases for your SSH keys to add an extra

layer of security.

Keep your private keys secure and never share them.

Use aliases in your config file to easily manage

multiple accounts.
4
The end !

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy