0% found this document useful (0 votes)
23 views9 pages

Git Hub

Uploaded by

vaiboro51
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)
23 views9 pages

Git Hub

Uploaded by

vaiboro51
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/ 9

Version control and Git

Version control is a system that allows developers to manage changes to their code over time. It
is an essential tool for software development as it enables multiple developers to work on the
same codebase simultaneously without the fear of overwriting each other's work.

Git is a popular version control system developed by Linus Torvalds in 2005. Git uses a
distributed architecture, which means that every developer has a copy of the entire repository
on their local machine. This allows developers to work offline and makes it easy to merge
changes between different branches of the codebase.

In Git, developers create a repository, which is a directory that contains all of the code and files
for a project. They then make changes to the code and use Git commands to track those
changes, create new versions of the code, and collaborate with other developers.

The core Git commands include:

• git init: creates a new Git repository

• git add: adds changes to the staging area

• git commit: creates a new version of the code

• git push: sends changes to a remote repository

• git pull: retrieves changes from a remote repository

• git merge: merges changes from one branch into another

Git also supports branching, which allows developers to create multiple versions of the
codebase that can be worked on independently. This is useful for testing new features or
making experimental changes without affecting the main codebase.

Overall, Git is a powerful tool that enables developers to work collaboratively on codebases,
track changes to the code over time, and manage complex projects with ease.

GitHub and its benefits


GitHub is a web-based platform that is built on top of Git, the version control system we
discussed earlier. It provides a graphical user interface and a suite of tools that make it easier for
developers to collaborate on code, share their work with others, and manage complex software
projects.

Some of the benefits of using GitHub include:

1. Collaborative Development: GitHub allows multiple developers to work together on


the same codebase, making it easy to share code and track changes over time.

1|Pa ge
Developers can use GitHub to review each other's code, suggest changes, and merge
contributions into the main codebase.

2. Code Hosting: GitHub provides a secure and reliable hosting service for code
repositories. Developers can store their code on GitHub, making it easily accessible to
anyone who needs it. GitHub also provides a powerful search engine that allows
developers to find and reuse code from other projects.

3. Issue Tracking: GitHub includes a built-in issue tracking system that allows developers
to keep track of bugs, feature requests, and other issues related to their projects. This
makes it easy to prioritize work, track progress, and communicate with other developers
and stakeholders.

4. Continuous Integration and Deployment: GitHub supports a range of tools and


integrations that make it easier to build, test, and deploy code. Developers can use
GitHub to automate the testing and deployment process, making it easier to release new
features and fixes quickly and reliably.

5. Open-Source Community: GitHub is home to a vibrant and active community of open-


source developers. Developers can use GitHub to discover and contribute to open-
source projects, learn from others, and build their reputations within the community.

Overall, GitHub is a powerful platform that enables developers to work collaboratively, share
their code with others, and manage complex software projects with ease. Its many features and
integrations make it an essential tool for modern software development.

Setting up GitHub Account:


To set up a GitHub account and create a basic profile, follow these steps:

1. Go to the GitHub website (https://github.com/) and click on the "Sign up" button in the
top right corner.

2. Enter your email address, choose a username and password, and click on the "Create
account" button.

3. On the next page, you'll be asked to choose your plan. GitHub offers a range of plans,
including a free plan for individual users. Select the plan that best suits your needs and
click on the "Continue" button.

4. You'll then be asked to provide some basic information, including your name and a brief
bio. You can also add a profile picture if you wish.

5. Once you've entered your information, click on the "Submit" button.

2|Pa ge
6. You'll then be taken to your GitHub dashboard, where you can create new repositories,
explore other projects, and manage your account settings.

7. To customize your profile, click on your profile picture in the top right corner and select
"Your profile". Here, you can add more details about yourself, including your location,
website, and social media profiles.

8. You can also customize your profile page by adding a profile README, which is a
markdown file that appears at the top of your profile. To do this, click on the "Add profile
README" button on your profile page, and then use the markdown editor to create your
README.

That's it! You've now set up a GitHub account and created a basic profile. From here, you can
start exploring GitHub and using it to collaborate on projects with others.

Basic Commands:
Here are some basic Git commands with examples:

1. git init: Initializes a new Git repository in the current directory.

Code: $ git init

A real-life scenario for using the git init command would be when you are starting a
new software development project and want to use Git for version control.

Assuming you have already created a new directory on your local machine for the project, you
can use the git init command to initialize a new Git repository in that directory.

Once you've initialized the repository, you can start adding files to it and making changes to
your code. You can use the git add command to add files to the staging area, and the git
commit command to create a new commit with the changes in the staging area.

As you continue to work on your project, you can use other Git commands like git status, git
log, and git branch to manage your repository and keep track of your changes.

When you're ready to share your project with others, you can push your changes to a remote
repository on a platform like GitHub or Bitbucket.

Overall, the git init command is a crucial first step when starting a new software development
project with Git. It creates a new repository and sets up the basic structure you'll need to start
version controlling your code.

2. git clone: Copies a Git repository from a remote source to your local machine.

3|Pa ge
Code: $ git clone https://github.com/user/repo.git

A real-life scenario for using the git clone command would be when you want to work
on an existing Git repository that is hosted on a remote server, such as on GitHub or Bitbucket.

Assuming you've already created a new directory on your local machine for the project, you can
use the git clone command to copy the repository from the remote source to your local
machine.

For example, if the remote repository is hosted on GitHub, you can go to the repository's page
on GitHub, copy the repository's URL, and then use the following command to clone the
repository:

This command will copy the entire repository to your local machine, including all of its files,
commit history, and branches. Once the repository has been cloned, you can start making
changes to the code and using Git commands like git add, git commit, and git push to
manage your changes.

Using git clone is especially useful when working on a project with multiple contributors, as
each contributor can clone the repository to their local machine and make changes without
affecting the original source code. This allows for easier collaboration and version control
among team members.

3. git add: Adds files to the staging area to be committed to the repository.

Code: $ git add file.txt

A real-life scenario for using the git add command would be when you've made changes
to your code and want to include those changes in the next commit.

For example, let's say you're working on a web application and have just added a new feature
that allows users to upload images. After making the necessary changes to your code, you can
use the git add command to add the modified files to the staging area, which is where changes
are stored before being committed to the repository.

$ git add app.py

$ git add templates/upload.html

In this example, you've added the modified app.py file and the new templates/upload.html file
to the staging area. These changes will now be included in the next commit.

Using git add is useful because it allows you to selectively choose which changes to include in
your next commit. You can add individual files, multiple files, or even specific lines within files
using the git add command. This helps you keep your commits organized and focused, which
can make it easier to track down issues and revert changes if necessary.

4|Pa ge
4. git commit: Creates a new commit with the changes in the staging area.

Code: $ git commit -m "Commit message"

A real-life scenario for using the git commit command would be when you've made
changes to your code and are ready to save those changes to the repository.

For example, let's say you're working on a web application and have just added a new feature
that allows users to reset their passwords. After adding the necessary code and using the git
add command to stage the changes, you can use the git commit command to create a new
commit with those changes.

$ git commit -m "Add password reset feature"

In this example, you've created a new commit with the message "Add password reset feature" to
describe the changes you've made. This commit will now be added to the repository's history
and can be viewed by others who are working on the project.

Using git commit is important because it allows you to keep a detailed record of all changes
made to the repository over time. Each commit includes a message that describes the changes
made, as well as a timestamp and the author of the commit. This makes it easier to track down
issues and revert changes if necessary, and also helps to provide context for other team
members who may be working on the same project.

5. git push: Sends your local commits to the remote repository.

Code: $ git push origin main

A real-life scenario for using the git push command would be when you're working on a
project with other contributors and want to share your changes with them.

For example, let's say you're working on a web application with two other developers, and
you've just finished adding a new feature that allows users to update their profile information.
After committing your changes using the git commit command, you can use the git push
command to push those changes to a remote repository, such as one hosted on GitHub.

In this example, you've pushed your changes to the master branch of the origin remote
repository. This will make your changes available to the other developers on the project, who
can then pull your changes to their local machines using the git pull command.

Using git push is important because it allows you to collaborate with other team members and
share your work with others. It also helps to keep everyone on the same page and ensures that
everyone is working with the latest version of the code. Additionally, using a remote repository

5|Pa ge
like GitHub provides a centralized location where all team members can view the project's
history and make contributions.

6. git pull: Fetches the latest changes from the remote repository and merges them into
your local branch.

Code: $ git pull origin main

A real-life scenario for using the git pull command would be when you're working on a
project with other contributors and want to incorporate changes made by others into your local
repository.

For example, let's say you're working on a web application with two other developers, and one
of them has just pushed some changes to the remote repository on GitHub. To incorporate
those changes into your local repository, you can use the git pull command.

$ git pull origin master

In this example, you're pulling changes from the master branch of the origin remote repository
into your local repository. This will merge any changes made by other contributors into your
local branch, allowing you to work with the latest version of the code.

Using git pull is important because it allows you to keep your local repository up to date with
changes made by other contributors. It also helps to prevent conflicts and ensure that everyone
is working with the same version of the code. By regularly pulling changes from the remote
repository, you can stay in sync with the rest of the team and ensure that your work is consistent
with the rest of the project.

7. git status: Shows the current status of the repository, including any changes that have
been made.

Code: $ git status

A real-life scenario for using the git status command would be when you're working on
a project and want to see which files have been modified since the last commit.

For example, let's say you're working on a web application and have just made some changes to
the app.py file. To see the status of your changes, you can use the git status command.

$ git status

In this example, running the git status command will show you that the app.py file has been
modified and needs to be added to the staging area before it can be committed.

6|Pa ge
Using git status is important because it allows you to keep track of which files have been
modified, which files are staged for commit, and which files are not being tracked by Git. This
can help you avoid accidentally committing changes that you didn't intend to, and can also help
you keep your commits organized and focused. Additionally, by using git status regularly, you
can stay aware of the state of your repository and avoid potential issues down the line.

8. git log: Displays a list of all commits in the repository.

Code: $ git log

A real-life scenario for using the git log command would be when you want to view a
detailed history of all the commits made to the repository.

For example, let's say you're working on a web application and want to see a list of all the
commits made to the master branch. To view this history, you can use the git log command.

$ git log

In this example, running the git log command will show you a list of all the commits made to
the master branch, along with the author, date, and commit message for each one.

Using git log is important because it allows you to see a detailed history of all the changes
made to the repository over time. This can help you track down issues, review the work of other
contributors, and provide context for the changes you've made. By using git log regularly, you
can stay up to date with the project's history and gain insights into how the codebase has
evolved over time.

9. git branch: Shows a list of all branches in the repository.

Code: $ git branch

A real-life scenario for using the git branch command would be when you want to
create a new branch to work on a specific feature or fix a bug, without affecting the main
codebase.

For example, let's say you're working on a web application and want to create a new branch
called feature/authentication to add a new authentication system. To create this branch, you
can use the git branch command.

$ git branch feature/authentication

In this example, running the git branch command will create a new branch called
feature/authentication based on the current branch you're on. This will allow you to work on
the new feature or bug fix without affecting the main codebase.

7|Pa ge
Using git branch is important because it allows you to work on specific features or bug fixes in
isolation, without affecting the main codebase. This can help you avoid conflicts with other
contributors, and also makes it easier to collaborate with other team members by keeping your
work separate from theirs. Additionally, by using branches, you can experiment with new ideas
and approaches without affecting the stability of the main codebase.

10. git checkout: Switches to a different branch or commit.

Code: $ git checkout branch_name

A real-life scenario for using the git checkout command would be when you want to
switch to a different branch or commit to work on a specific feature or fix a bug.

For example, let's say you're working on a web application and have created a new branch called
feature/authentication to add a new authentication system. To switch to this branch, you can
use the git checkout command.

$ git checkout feature/authentication

In this example, running the git checkout command will switch you to the
feature/authentication branch, allowing you to work on the new feature or bug fix.

Using git checkout is important because it allows you to switch between different branches or
commits to work on specific features or bug fixes. This can help you avoid conflicts with other
contributors and make it easier to collaborate with other team members by keeping your work
separate from theirs. Additionally, by using git checkout, you can easily test different versions
of the code and experiment with new ideas and approaches.

These are just some of the most commonly used Git commands. There are many more
commands and options available, depending on your specific needs and workflow.

GitHub workflow

GitHub workflow is a process that allows individuals or teams to collaborate on a project using
Git and GitHub. It typically involves the following steps:

1. Create a new repository: First, you create a new repository on GitHub or clone an
existing repository to your local machine using Git.

2. Create a branch: You create a new branch to work on a specific feature or bug fix. This
allows you to work on the changes without affecting the main codebase.

8|Pa ge
3. Make changes and commit: You make changes to the code and commit them to the
branch. Each commit should be small, focused, and well-documented.

4. Create a pull request: Once you have made your changes and committed them to the
branch, you create a pull request (PR) to merge your changes into the main codebase.
The PR allows you to review the changes, discuss them with others, and get feedback
before merging them.

5. Review and merge: The PR is reviewed by other team members, who may suggest
changes or ask for clarification. Once the PR is approved, it can be merged into the main
codebase.

6. Test and deploy: After the changes have been merged, the code is tested to ensure that
everything is working as expected. Once the tests pass, the changes can be deployed to
production.

7. Repeat: The process is repeated for each new feature or bug fix, with each change being
made on a new branch and merged via a pull request.

Using a GitHub workflow helps teams collaborate more effectively and ensures that changes are
well-documented, reviewed, and tested before being merged into the main codebase. It also
makes it easier to keep track of changes over time, revert to previous versions if needed, and
collaborate across different time zones and locations.

-----END-----

Muntasir Abdullah Mizan


[email protected]

9|Pa ge

You might also like