2. Git and Key concepts
Advantages of Git over other Version
Control Systems
Basic Git Commands and Concepts
3. By the end of the session, we will be able to:
▪ Grasp the significance of version control.
▪ Successfully install and configure Git on their
Windows machines.
▪ Create a new Git repository in their project directory.
▪ Navigate the commit history of their repository.
Session Objectives
4. Install Git On Windows
Configuration of Git
Creating a Git Repository and
Connecting it to a Remote Repository
5. Install Git On Windows
● To download the latest version of Git, click on the
link below:
● https://git-scm.com/download/win/
● Great! Your file is being downloaded.
6. Install Git On Windows
● After your download is complete, Run the .exe file
in your system.
7. Install Git On Windows
● After you have pressed the Run button and agreed
to the license, you will find a window prompt to
select components to be installed.
● After you have made a selection of your desired
components, click on Next>.
8. Install Git On Windows
● The next prompt window will let you choose the
adjustment of your path environment. This is
where you decide how you want to use Git.
● You can select any of the three options according
to your needs. But for beginners, I recommend
using Use Git From Git Bash Only
9. Install Git On Windows
● The next step is to choose features for your Git.
You get three options and you can choose any of
them, all of them or none of them as per your
needs. Let me tell you what these features are
● The first is the option to Enable file system
caching.
● Caching is enabled through Cache Manager, which
operates continuously while Windows is running.
File data in the system file cache is written to the
disk at intervals determined by the operating
system, and the memory previously used by that
file data is freed.
10. Install Git On Windows
● The second option is to enable Git Credential
Manager.
● The Git Credential Manager for Windows (GCM) is a
credential helper for Git. It securely stores your
credentials in the Windows CM so that you only need
to enter them once for each remote repository you
access. All future Git commands will reuse the
existing credentials.
● The third option is to Enable symbolic links.
● Symbolic links or symlinks are nothing but advanced
shortcuts. You can create symbolic links for each
individual file or folder, and these will appear like they
are stored in the folder with symbolic links.
● I have selected the first two features only.
11. Install Git On Windows
● Choose your terminal.
● You can choose one from the options.
● The default terminal of MYSYS2 which is a
collection of GNU utilities such as bash, make,
gawk and grep to allow building of applications and
programs which depend on traditionally UNIX tools
to be present.
● Or you can choose the window’s default console
window (cmd.exe).
12. Install Git On Windows
● Now you have got all you need. Select Launch Git
Bash and click on Finish.
● This will launch Git Bash on your screen.
13. Install Git On Windows
Configuration of Git
Creating a Git Repository and connecting
it to a Remote Repository
14. Configuration of Git
● After installing Git, you need to configure it with
your user information, including your name and
email address. This information will be associated
with your commits.
● Open a terminal or Git Bash (on Windows) and run
the following commands to configure Git:
git config --global user.name "Your
Name"
git config --global user.email
"yourname@example.com"
● Replace "Your Name" with your actual name and
"yourname@example.com" with your email
address.
15. Configuration of Git
● The --global flag sets the configuration globally,
meaning it will be applied to all repositories on
your system. If you want to set configuration on a
per-repository basis, omit the --global flag and run
the commands inside the specific repository.
● You can verify your configuration by running the
following command:
git config --global –list
● This will display your configured name and email
address.
16. Configuration of Git
● Checking the Git Installation: To ensure that Git is
installed correctly, open a terminal or Git Bash and
run the following command:
git --version
● This command will display the installed Git
version, confirming that Git is properly installed on
your system.
17. Install Git On Windows
Configuration of Git
Creating a Git Repository and connecting
it to a Remote Repository
18. Creating a Git Repository
● In Git, a repository is a central location where your
project's files and version history are stored. In this
part of the chapter, we will explore the process of
creating a Git repository on your local machine.
● Creating a Git Repository: To create a Git
repository, follow these steps:
Navigate to the desired directory:
● Open a terminal or command prompt and navigate
to the directory where you want to create the Git
repository. This directory will serve as the root of
your project.
19. Creating a Git Repository
Initialize the repository:
● Run the following command to initialize a new Git
repository in the current directory:
git init
● This command creates an empty Git repository in the
current directory. You will see a new hidden folder
named ".git" that contains the repository's
metadata.
Adding files to the repository:
● Once the repository is initialized, you can start
adding files to it. Copy or create the files you want to
include in the repository into the project directory.
20. Creating a Git Repository
Staging and committing changes:
● Git uses a staging area to track changes before
committing them. To stage changes, use the
following command:
git add <file1> <file2> ...
● Replace <file1>, <file2>, etc., with the names of the
files you want to stage. Use "." to stage all changes
in the current directory.
● After staging the changes, you can commit them
using the following command:
git commit -m "Commit message"
21. Creating a Git Repository
Staging and committing changes:
● Replace "Commit message" with a descriptive
message summarizing the changes made in the
commit. This helps you and others understand the
purpose of the commit.
● Viewing the repository's history: You can view the
commit history of the repository using the following
command:
git log
● This command displays a list of commits, including
their unique identifiers, author information,
timestamps, and commit messages. The log
provides an overview of the project's version
history.
22. Connecting to a Remote Repository
● Connecting to a remote repository allows you to
collaborate with others, synchronize your changes,
and share your work. In this part, we will explore the
process of connecting to a remote repository.
● Creating a remote repository: To connect to a
remote repository, you first need to create one.
There are various hosting platforms available, such
as GitHub, GitLab, and Bitbucket.
● Follow the instructions provided by your chosen
platform to create a new repository.
23. Connecting to a Remote Repository
● Associating the remote repository: After creating
the remote repository, you need to associate it with
your local repository. Run the following command
to add the remote repository URL:
git remote add origin <remote_url>
● Replace <remote_url> with the URL of the remote
repository.
● Pushing changes to the remote repository: To
upload your local commits to the remote repository,
use the following command:
git push -u origin <branch_name>
24. Connecting to a Remote Repository
● Replace <branch_name> with the branch you want
to push to the remote repository. The -u option sets
the upstream branch, allowing you to use git push
in the future without specifying the branch.
● Pulling changes from the remote repository: To
retrieve and incorporate changes made in the
remote repository, use the following command:
git pull origin <branch_name>
● Replace <branch_name> with the branch you want
to pull changes from. This command fetches the
latest changes and merges them into your local
branch.
25. Install Git On Windows
Configuration of Git
Creating a Git Repository and
connecting it to a Remote Repository