ALX LESSON
Git - Github
Source Code Management (SCM)
TABLE OF CONTENTS
01 02
Overview Learning
topics Objectives
03 04
Quiz hands on lab
questions practice
01
OVERVIEW topics
OVERVIEW Topics
What is source code management
What is Git
What is GitHub
What is the difference between Git
and GitHub
How to create a repository
Git What is a README
How to write good READMEs
GitHub How to commit
How to write helpful commit
Topics messages
How to push code
How to pull updates
How to create a branch
How to merge branches
How to work as collaborators on a
Bonus * How to delete branch project
Which files should and which files
should not appear in your repo
02
Learning Objectives
What is source code management
Source code management (SCM) is the practice of tracking and managing changes to
source code over time. It is a way for developers to collaborate on code, track changes,
and maintain versions of their codebase. SCM tools provide a central repository where
developers can store and manage code, and enable them to track changes, collaborate
with others, and revert to previous versions if needed.
Examples:
Git: Git is one of the most popular SCM tools and is used by millions of developers
SVN (Subversion) - Mercurial - Perforce - TFS (Team Foundation Server)
What is Git
Git is a distributed version control system
used for source code management. It was
created by Linus Torvalds in 2005 and has
become one of the most popular SCM tools in
use today.
Git allows multiple developers to work on the
same codebase simultaneously and provides a
way to track changes, collaborate on code, and
maintain different versions of the code.
What is GitHub
GitHub is a web-based hosting service for Git
repositories. It provides a platform for
developers to collaborate on code, track
changes, and manage versions of their
codebase.
GitHub also provides additional features such
as issue tracking, wikis, and project
management tools.
What is the difference between Git and GitHub
Git is a distributed version control system
used for source code management,
while GitHub is a web-based hosting service
for Git repositories.
Git provides the underlying functionality for
version control,
while GitHub provides a platform for
collaboration and additional features such as
issue tracking, project management, and
wikis.
How to create a repository
Log in to your GitHub account.
Click the "New repository" button.
Enter a name for your repository, and add a
description if desired.
Choose whether the repository will be public
or private.
Select the option to initialize the repository
with a README file.
Click the "Create repository" button.
What is a README
A README is a file in a code repository that
contains information about the codebase. It
typically includes a description of the project,
instructions on how to use the code, and any
other relevant information.
What is a README
To write a good README, follow these tips:
-Use clear, concise language.
-Include a description of the project.
-Provide instructions on how to install and
use the code.
-Include any relevant screenshots or images.
-Explain any dependencies or requirements.
-Provide information on how to contribute to
the project.
-Include a license if appropriate.
-Keep the README up to date as the project
evolves.
How to commit
To commit changes to your Git repository,
follow these steps:
Make changes to your code.
Use the git add . command to stage the
changes you want to commit.
Use the git commit –m “” command to create a
commit with a message that describes the
changes you made.
How to write helpful commit messages
When writing commit messages, it's important
to be clear and descriptive about the changes
you made. Here are some tips for writing
helpful commit messages:
Start with a short summary of the changes you
made, for example:
Fix bug in login form validation
Add new feature to search results page
Refactor authentication middleware for
improved performance
Update README with instructions for running
tests
How to push code
To push code to a remote Git repository,
follow these steps:
Use the `git add . ` command to stage the
changes you want to push.
Use the `git commit –m “message” ` command
to create a commit with a message describing
the changes.
Use the `git push origin branch_name`
command to push the changes to the remote
repository.
How to pull updates
git pull is a Git command that retrieves and
merges the changes from a remote repository
into the local repository.
When you run git pull, Git fetches the changes
from the remote repository and incorporates
them into your current branch. This is a
combination of two Git commands: git fetch
and git merge. The git fetch command
downloads the changes from the remote
repository into your local repository, while
the git merge command combines those
When you run git remote update, Git fetches changes into your current branch.
any changes that have been made to the
remote repository since the last time you Prefered to
updated your local references. This includes git remote update
new branches or tags that have been created, git pull origin “branch_name”
or updates to existing branches or tags.
How to create a branch
To create a new branch in Git, follow these
steps:
Use the git branch “branch name” command to
create a new branch.
Use the git checkout “branch name” command
to switch to the new branch.
Alternatively, you can create and switch to a
new branch with a single command:
git checkout -b “branch name”
How to merge branches
Use the git checkout “branch name” command
to switch to the branch you want to merge
changes into.
Use the git merge command to merge changes
from the other branch into the current branch.
How to work as collaborators on a project
To work as collaborators on a project in Git,
follow these steps:
Create a shared Git repository that all
collaborators can access.
Assign roles and permissions to each
collaborator.
Create branches for each feature or issue.
Have each collaborator work on their assigned
branch.
Use pull requests to review and merge
changes into the main branch.
Which files should and which files should not appear in your repo
The .gitignore file is a configuration file that
specifies which files and directories Git
should ignore when tracking changes in a
repository.
You can create a .gitignore file in the root
directory of your repository and add file
patterns to it to exclude certain files and
directories from being tracked by Git.
Which files should and which files should not appear in your repo
Here are some general guidelines on which
files should and should not be included in a
Git repository:
Include all source code files that are
necessary to build and run your project.
Exclude generated files, such as compiled
binaries or build artifacts.
Exclude files that contain sensitive
information, such as passwords, API keys, or
other credentials.
Exclude configuration files that contain
machine-specific settings or environment
variables.
Which files should and which files should not appear in your repo
Sure, here is an example of how to create a .gitignore file
for a Node.js project:
Open a text editor and create a new file in the root
directory of your project.
Save the file as .gitignore (note the leading dot).
In the file, add patterns for the files and directories that
you want Git to ignore. Here's an example:
# Ignore node_modules directory
node_modules/
# Ignore log files
*.log
# Ignore environment configuration files
.env*
How to delete branches
Make sure you are on a different branch than
the one you want to delete. You cannot delete
the branch you are currently on.
git checkout <another-branch>
Delete the branch using the
git branch –d ‘branch name’ command.
Example:
git branch -d my-branch
How to delete branches
Note that if the branch has not been fully
merged, you will get an error message. In that
case, you can use the -D option to force the
deletion of the branch, even if it has not been
fully merged:
git branch -D my-branch
This will delete the branch, including all of
its commits and changes.
Verify that the branch has been deleted by
listing all of the branches in your repository.
By git branch
The branch you just deleted should no longer
appear in the list.
03
Quiz questions
04
Hands on lab Practice
Have a Question
Leave a Comment!
Subscribe
To stay updated with latest
videos
Share
To let the others know more
Thanks