0% found this document useful (0 votes)
28 views40 pages

Git Hub

Uploaded by

Thivi Roopan
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)
28 views40 pages

Git Hub

Uploaded by

Thivi Roopan
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/ 40

GitHub

Chandana Wijesuriya (MBA in Project Management, B.Sc sp Hons IT, CSM®)


Summary
You’ll learn how to:
• Create and use a repository
• Start and manage a new branch
• Make changes to a file and push them to GitHub as commits
• Open and merge a pull request
• Common GIT commands
• Working with local repositories

Chandana Wijesuriya (MBA in Project Management, B.Sc sp Hons IT, CSM®)


Chandana Wijesuriya (MBA in Project Management, B.Sc sp
Hons IT, CSM®)
What is GitHub?
• GitHub is a code hosting platform for version control and
collaboration. It lets you and others work together on projects from
anywhere.
• During the lecture we will discuss about GitHub essentials like
repositories, branches, commits, and Pull Requests.
• You’ll create your own name_SQA repository and learn GitHub’s Pull
Request workflow, a popular way to create and review code.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
What is GitHub?
• To complete this tutorial, you need a GitHub.com account and
Internet access.
• You don’t need to know how to code, use the command line, or install
Git (the version control software GitHub is built on).

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Chandana Wijesuriya (MBA in Project Management, B.Sc sp Hons IT, CSM®)
Chandana Wijesuriya (MBA in Project Management, B.Sc sp
Hons IT, CSM®)
Step 1. Create a Repository
• A repository is usually used to organize a single project.
• Repositories can contain folders and files, images, videos,
spreadsheets, and data sets – anything your project needs.
• Recommend including a README, or a file with information about
your project.
• GitHub makes it easy to add one at the same time you create your
new repository. It also offers other common options such as a license
file.
• Your name_SQA repository can be a place where you store ideas,
resources, or even share and discuss things with others.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Step 1. Create a Repository
create a new repository

1. In the upper right corner, next to your avatar or identicon, click


and then select New repository.
2. Name your repository hello-world.
3. Write a short description.
4. Select Initialize this repository with a README.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Name_SQA

 Click Create repository


Chandana Wijesuriya (MBA in Project Management, B.Sc sp
Hons IT, CSM®)
Step 2. Create a Branch
• Branching is the way to work on different versions of a repository at
one time.
• By default your repository has one branch named master which is
considered to be the definitive branch.
• We use branches to experiment and make edits before committing
them to master.
• When you create a branch off the master branch, you’re making a
copy, or snapshot, of master as it was at that point in time.
• If someone else made changes to the master branch while you were
working on your branch, you could pull in those updates.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
What is a Branch ?

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Step 2. Create a Branch

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Step 2. Create a Branch
• The diagram shows:

 The master branch


 A new branch called feature (because we’re doing ‘feature work’
on this branch)
 The journey that feature takes before it’s merged into master

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Step 2. Create a Branch
• Have you ever saved different versions of a file? Something like:
- Story.txt
- Story-SQA-edit.txt
- Story-SQA-edit-reviewed.txt
• Branches accomplish similar goals in GitHub repositories.
• Developers, writers, and designers use branches for keeping bug fixes
and feature work separate from our master (production) branch.
• When a change is ready, they merge their branch into master.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
2.1 How to create a new branch
• Go to your new repository “name_SQA”.
• Click the drop down at the top of the file list that says branch: master.
• Type a branch name, readme-edits, into the new branch text box.
• Select the blue Create branch box or hit “ENTER” on your keyboard.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
2.1 How to create a new branch

Name_SQA

Name_SQA_Branch1

Name_SQA_Branch1
Chandana Wijesuriya (MBA in Project Management, B.Sc sp
Hons IT, CSM®)
2.1 How to create a new branch
Name_SQA

Name_SQA

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
2.1 How to create a new branch
• Now you have two branches, master and Name_SQA_Branch1.
• They look exactly the same, but not for long! Next we’ll add our
changes to the new branch.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Step 3. Make and commit changes

• Bravo! Now, you’re on the code view for your Name_SQA_Branch1,


which is a copy of master. Let’s make some edits.
• On GitHub, saved changes are called commits.
• Each commit has an associated commit message, which is a
description explaining why a particular change was made.
• Commit messages capture the history of your changes, so other
contributors can understand what you’ve done and why.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Step 3. Make and commit changes
• Make and commit changes
1. Click the name_SQA.md file.
2. Click the pencil icon in the upper right corner of the file view to
edit.
3. In the editor, write a bit about yourself.
4. Write a commit message that describes your changes.
5. Click Commit changes button.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Step 3. Make and commit changes
Name_SQA

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Step 4. Open a Pull Request

• Now that you have changes in a branch off of master, you can open a
pull request.
• Pull Requests are the heart of collaboration on GitHub.
• When you open a pull request, you’re proposing your changes and
requesting that someone review and pull in your contribution and
merge them into their branch.
• Pull requests show diffs, or differences, of the content from both
branches. The changes, additions, and subtractions are shown in
green and red.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Step 4. Open a Pull Request

• As soon as you make a commit, you can open a pull request and start
a discussion, even before the code is finished.
• By using GitHub’s @mention system in your pull request message,
you can ask for feedback from specific people or teams, whether
they’re down the hall or 10 time zones away.
• You can even open pull requests in your own repository and merge
them yourself. It’s a great way to learn the GitHub Flow before
working on larger projects.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Open a Pull Request for changes to the README
1. Click the Pull Request tab, then from the Pull Request page, click
the green New pull request button.
2. In the Example Comparisons box, select the branch you made,
readme-edits, to compare with master (the original).
3. Look over your changes in the diffs on the Compare page, make
sure they’re what you want to submit.
4. When you’re satisfied that these are the changes you want to
submit, click the big green Create Pull Request button.
5. Give your pull request a title and write a brief description of your
changes.
6. When you’re done with your message, click Create pull request!

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Step 5. Merge your Pull Request

• In this final step, it’s time to bring your changes together – merging
your readme-edits branch into the master branch.
1. Click the green Merge pull request button to merge the changes
into master.
2. Click Confirm merge.
3. Go ahead and delete the branch, since its changes have been
incorporated, with the Delete branch button in the purple box.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Step 5. Merge your Pull Request

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Celebrate!
• Created an open source repository

• Started and managed a new branch

• Changed a file and committed those


changes to GitHub

• Opened and merged a Pull Request

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Working with local repositories
GIT Command Syntax Description
git init $ git init This command turns a directory into an empty Git
repository. This is the first step in creating a
repository. After running git init, adding and
committing files/directories is possible.
git add $ git add <file or directory Adds files in the to the staging area for Git. Before a
name> file is available to commit to a repository, the file
needs to be added to the Git index (staging area).
git commit $ git commit -m "Commit Record the changes made to the files to a local
message in quotes" repository. For easy reference, each commit has a
unique ID.
git status $ git status This command returns the current state of the
repository.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Working with local repositories
GIT Command Syntax Description
git config $ git config <setting> With Git, there are many configurations and settings
<command> possible. git config is how to assign these settings.
Two important settings are user user.name and
user.email. These values set what email address and
name commits will be from on a local computer.
1) $ git branch To determine what branch the local repository is on,
<branch_name> add a new branch, or delete a branch.
2) $ git branch –a 1) Create new branch
3) $ git branch -d 2) List all local and remote branches
<branch_name> 3) Delete branch
git checkout $ git checkout To start working in a different branch, use git
<branch_name> checkout to switch branches.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Working with local repositories
GIT Command Syntax Description
git merge $ git merge Integrate branches together. git merge combines the
<branch_name> changes from one branch to another branch.
git clone $ git clone <remote_URL> To create a local working copy of an existing remote
repository, use git clone to copy and download the
repository to a computer.
git pull $ git pull <branch_name> To get the latest version of a repository run git pull.
<remote_URL/remote_na This pulls the changes from the remote repository to
me> the local computer.
git push 1) $ git push Sends local commits to the remote repository. git
<remote_URL/remote_na push requires two parameters: the remote
me> <branch> repository and the branch that the push is for.
2) $ git push —all

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Adding an existing project to GitHub using the
command line
1. Putting your existing work on GitHub can let you share and
collaborate in lots of great ways
2. Create a new repository on GitHub. To avoid errors, do not initialize
the new repository with README, license, or gitignore files.
3. You can add these files after your project has been pushed to
GitHub.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Adding an existing project to GitHub using the
command line
4. Open Git Bash.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Adding an existing project to GitHub using the
command line
5. Change the current working directory to your local project.
6. Initialize the local directory as a Git repository.

7. Add the files in your new local repository. This stages them for the
first commit.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Adding an existing project to GitHub using the
command line
8. Add the files in your new local repository. This stages them for the
first commit.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Adding an existing project to GitHub using the
command line
9. At the top of your GitHub repository's Quick Setup page, click to copy
the remote repository URL.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Adding an existing project to GitHub using the
command line
10. In the Command prompt, add the URL for the remote repository
where your local repository will be pushed.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Adding an existing project to GitHub using the
command line
11. Push the changes in your local repository to GitHub.

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
Source
• https://guides.github.com/introduction/flow/
• https://github.com/explore
• https://help.github.com/articles/viewing-contributions-on-your-
profile/
• https://guides.github.com/

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)
THANK YOU

Chandana Wijesuriya (MBA in Project Management, B.Sc sp


Hons IT, CSM®)

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