SlideShare a Scribd company logo
1 of 53
Introduction to
git
Objective
• At the end of this session, you will be able to:
• Install git
• Create a local git repository
• Add a file to the repo
• Add a file to staging
• Create a commit
• Create a new branch
• Create a GitHub repo
• Push a branch to GitHub
Sad Story ….
Version control
• Version
control
also known as revision control
or source control, is the management of
changes to documents, computer
programs, large web sites, and other
collections of information.
• Version control systems (VCS)
Version control systems are a category of software tools that help a software team manage
changes to source code over time.
Version control software keeps track of every modification to the code in a special kind of
database.
Version control examples
Version control examples
Version control examples
Git
• Git
Git is a free and open source distributed version control
system designed to handle everything from small to very
large projects with speed and efficiency.
Git is easy to learn and has a tiny footprint with lightning
fast performance. Learn more about git here.
• Prerequisites
You will need a GitHub account
(it's free). Go to
https://github.com/join and set
up a GitHub account if you do not
have one already.
Install git
• Install git
Start by installing git on your
instance. When you're working
on your own projects, it is
always a good idea to check
for updates even if you already
have git installed. You can
install it as a package, via
another installer, or download
the source code and compile it
yourself
• Ubuntu
• Verify your installation
with the following
command:
Create a local git
repository
• Create a local git repository
Now that git is installed, create a new repository (or repo for short) to hold your release notes.
When you work on your own projects, you can create repositories in any directory you want.
1. Create a directory for your project with the mkdir (make directory) command:
• Create a local git repository
Then open the directory with the cd (change directory) command.
• Create a local git repository
Now, initialize your new git repository in the folder with the git init
command:
• Congratulations! You just initialized a git repository.
Add a file to the
repo
• Add a file to the repo
Your repository is empty. It's time to put something in it!
Add a new file to the project. You can use any text editor you like when you are
working on your own projects, but for this lab, simply create a new file with the
touch command.
Replace <file name> with a name for your file:
• Add a file to the repo
Run the ls (list) command to verify that the file was created in your project
directory:
• Add a file to the repo
Check to see which files git knows about with the git status command:
Add a file to
staging
Staging Area
Staging Area
• Add a file to staging
The next step is to add your file to the staging environment (sometimes referred
to as the index). You must do this before you commit a file. When you're
working, use the staging environment as just that - a staging ground - for
actively editing your files.
• Add a file to staging
Run the git status command again
• Notice the "Changes to be committed" line. You will see that git added
your file to the staging environment, but the file has not yet been
added to a commit.
New Branch
New Branch
Create a commit
• Create a commit
A commit is a record of what files you have changed since the last commit.
Commits allow you to go back to the state of the project at any point in history.
You create a commit in order to add files to the Master.
• Create a commit
First you need to identify yourself, then you can create the commit.
Run the following, filling in any email for "you@example.com":
• Create a commit
Run the following, filling in any name for "Your Name":
• Create a commit
Run the following git commit command. Your message should relate to what's in
your commit - for posterity:
Create a new
branch
• Create a new branch
Since you're on the master branch already, run the git checkout -b command and name
your branch. The command will:
Automatically create a new branch, using the name you specify
Immediately check the branch out to you
Move you to the new branch
• Create a new branch
• Create a new branch
Confirm that your branch was created:
Switch back to the master branch.
• Create a new branch
Make another file and add it:
• Create a new branch
Use git commit -m "Your message about the commit" to stage your changes.
Return to your branch.
Create a GitHub
repo
• Create a GitHub repo
If you're the sole owner of your project, you don't need to use GitHub. But if
you're on a team, you can use GitHub to collaborate without stepping on each
others' toes.
To create a new repo on GitHub, go to github.com and log in.
Click New repository:
• Create a
GitHub
repo
• GitHub will ask you for some basic info about your repo. Fill
out the form, then click Create repository.
• GitHub will ask you if you want to start from scratch or add a
local project. Since you just created a new repo, you want to
push that to GitHub. Follow the "...or push an existing
repository from the command line" section. Click the clipboard
to copy the commands.
• Create a GitHub repo
Return to your SSH window and run the commands you copied from GitHub.
• Create a GitHub repo
Note You will be prompted to log in. Use your GitHub credentials.
• The first command adds the local repository to your GitHub repository.
• The second command pushes your local repo to GitHub.
Push a branch to
GitHub
• Push a branch to GitHub
Pushing the commit in your branch to your new GitHub repo allows other
people to see the changes you've made (think code review). The repository's
owner can review changes prior to merging to the master branch.
Run the following command to push changes onto a new branch on GitHub,
replacing branch name with a name of your branch. Does GitHub automatically
create the branch for you on the remote repository?
• Push a branch to GitHub
• Push a branch to GitHub
In GitHub, click on the Code tab. You should now see the branch name you just pushed.
Click the Compare & pull request button that is next to your branch name.
You'll now see the name of your commit. In a production environment you could leave a
comment about this commit. For this lab click Create pull request.
GitHub verifies that the files you are adding aren't in conflict with the Master copy. If everthing
checks out, and it should since these are new files, you will see a green check mark. Click Merge
pull request, then Confirm merge.
You'll see a "Pull request successfully merged and closed" message. At this point you can click
Delete branch to clean up. You don't have to do this, but you may end up with a mess if you
have too many branches. Notice that you'll have another chance to leave comments.
Thank You

More Related Content

What's hot

Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Simplilearn
 

What's hot (20)

Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
git and github
git and githubgit and github
git and github
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
 
Github
GithubGithub
Github
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and Concepts
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using Git
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
 
Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagrams
 
Introduction to github slideshare
Introduction to github slideshareIntroduction to github slideshare
Introduction to github slideshare
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Git basic
Git basicGit basic
Git basic
 
Github
GithubGithub
Github
 

Similar to Introduction to Git and GitHub Part 1

Similar to Introduction to Git and GitHub Part 1 (20)

Version control git day02
Version control   git day02Version control   git day02
Version control git day02
 
Version control git day02
Version control   git day02Version control   git day02
Version control git day02
 
Git and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slideGit and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slide
 
Using git hub for your code
Using git hub for your codeUsing git hub for your code
Using git hub for your code
 
A Tutorial for GitHub.pdf
A Tutorial for GitHub.pdfA Tutorial for GitHub.pdf
A Tutorial for GitHub.pdf
 
A Tutorial for GitHub.pdf
A Tutorial for GitHub.pdfA Tutorial for GitHub.pdf
A Tutorial for GitHub.pdf
 
Git and Github.pptx
Git and Github.pptxGit and Github.pptx
Git and Github.pptx
 
Let's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHubLet's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHub
 
Using Git to Organize Your Project
Using Git to Organize Your ProjectUsing Git to Organize Your Project
Using Git to Organize Your Project
 
Brief tutorial on Git
Brief tutorial on GitBrief tutorial on Git
Brief tutorial on Git
 
16 Git
16 Git16 Git
16 Git
 
Version control git day01
Version control   git day01Version control   git day01
Version control git day01
 
Version control git day01
Version control   git day01Version control   git day01
Version control git day01
 
Git ritesh venture_pact
Git ritesh venture_pactGit ritesh venture_pact
Git ritesh venture_pact
 
Contributing to github is for everyone
Contributing to github is for everyoneContributing to github is for everyone
Contributing to github is for everyone
 
Advance workshop on git
Advance workshop on gitAdvance workshop on git
Advance workshop on git
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
Get your Git on GitHub
Get your Git on GitHubGet your Git on GitHub
Get your Git on GitHub
 
GDSC Git event 2023.pptx
GDSC Git event 2023.pptxGDSC Git event 2023.pptx
GDSC Git event 2023.pptx
 
Git & Github
Git & GithubGit & Github
Git & Github
 

More from Omar Fathy (8)

Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Cloud Run and Containers
Cloud Run and ContainersCloud Run and Containers
Cloud Run and Containers
 
GitOps and ArgoCD
GitOps and ArgoCDGitOps and ArgoCD
GitOps and ArgoCD
 
DevOps! What, Why and How?
DevOps! What, Why and How?DevOps! What, Why and How?
DevOps! What, Why and How?
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computing
 
Capture The Flag
Capture The FlagCapture The Flag
Capture The Flag
 
Google Cloud Fundamentals
Google Cloud Fundamentals Google Cloud Fundamentals
Google Cloud Fundamentals
 
Introduction to Git and GitHub Part 2
Introduction to Git and GitHub Part 2Introduction to Git and GitHub Part 2
Introduction to Git and GitHub Part 2
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Introduction to Git and GitHub Part 1

  • 2. Objective • At the end of this session, you will be able to: • Install git • Create a local git repository • Add a file to the repo • Add a file to staging • Create a commit • Create a new branch • Create a GitHub repo • Push a branch to GitHub
  • 4.
  • 6. • Version control also known as revision control or source control, is the management of changes to documents, computer programs, large web sites, and other collections of information.
  • 7. • Version control systems (VCS) Version control systems are a category of software tools that help a software team manage changes to source code over time. Version control software keeps track of every modification to the code in a special kind of database.
  • 11. Git
  • 12. • Git Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git is easy to learn and has a tiny footprint with lightning fast performance. Learn more about git here.
  • 13. • Prerequisites You will need a GitHub account (it's free). Go to https://github.com/join and set up a GitHub account if you do not have one already.
  • 15. • Install git Start by installing git on your instance. When you're working on your own projects, it is always a good idea to check for updates even if you already have git installed. You can install it as a package, via another installer, or download the source code and compile it yourself
  • 17. • Verify your installation with the following command:
  • 18. Create a local git repository
  • 19. • Create a local git repository Now that git is installed, create a new repository (or repo for short) to hold your release notes. When you work on your own projects, you can create repositories in any directory you want. 1. Create a directory for your project with the mkdir (make directory) command:
  • 20. • Create a local git repository Then open the directory with the cd (change directory) command.
  • 21. • Create a local git repository Now, initialize your new git repository in the folder with the git init command: • Congratulations! You just initialized a git repository.
  • 22. Add a file to the repo
  • 23. • Add a file to the repo Your repository is empty. It's time to put something in it! Add a new file to the project. You can use any text editor you like when you are working on your own projects, but for this lab, simply create a new file with the touch command. Replace <file name> with a name for your file:
  • 24. • Add a file to the repo Run the ls (list) command to verify that the file was created in your project directory:
  • 25. • Add a file to the repo Check to see which files git knows about with the git status command:
  • 26. Add a file to staging
  • 29. • Add a file to staging The next step is to add your file to the staging environment (sometimes referred to as the index). You must do this before you commit a file. When you're working, use the staging environment as just that - a staging ground - for actively editing your files.
  • 30. • Add a file to staging Run the git status command again • Notice the "Changes to be committed" line. You will see that git added your file to the staging environment, but the file has not yet been added to a commit.
  • 34. • Create a commit A commit is a record of what files you have changed since the last commit. Commits allow you to go back to the state of the project at any point in history. You create a commit in order to add files to the Master.
  • 35. • Create a commit First you need to identify yourself, then you can create the commit. Run the following, filling in any email for "you@example.com":
  • 36. • Create a commit Run the following, filling in any name for "Your Name":
  • 37. • Create a commit Run the following git commit command. Your message should relate to what's in your commit - for posterity:
  • 39. • Create a new branch Since you're on the master branch already, run the git checkout -b command and name your branch. The command will: Automatically create a new branch, using the name you specify Immediately check the branch out to you Move you to the new branch
  • 40. • Create a new branch
  • 41. • Create a new branch Confirm that your branch was created: Switch back to the master branch.
  • 42. • Create a new branch Make another file and add it:
  • 43. • Create a new branch Use git commit -m "Your message about the commit" to stage your changes. Return to your branch.
  • 45. • Create a GitHub repo If you're the sole owner of your project, you don't need to use GitHub. But if you're on a team, you can use GitHub to collaborate without stepping on each others' toes. To create a new repo on GitHub, go to github.com and log in. Click New repository:
  • 46. • Create a GitHub repo • GitHub will ask you for some basic info about your repo. Fill out the form, then click Create repository. • GitHub will ask you if you want to start from scratch or add a local project. Since you just created a new repo, you want to push that to GitHub. Follow the "...or push an existing repository from the command line" section. Click the clipboard to copy the commands.
  • 47. • Create a GitHub repo Return to your SSH window and run the commands you copied from GitHub.
  • 48. • Create a GitHub repo Note You will be prompted to log in. Use your GitHub credentials. • The first command adds the local repository to your GitHub repository. • The second command pushes your local repo to GitHub.
  • 49. Push a branch to GitHub
  • 50. • Push a branch to GitHub Pushing the commit in your branch to your new GitHub repo allows other people to see the changes you've made (think code review). The repository's owner can review changes prior to merging to the master branch. Run the following command to push changes onto a new branch on GitHub, replacing branch name with a name of your branch. Does GitHub automatically create the branch for you on the remote repository?
  • 51. • Push a branch to GitHub
  • 52. • Push a branch to GitHub In GitHub, click on the Code tab. You should now see the branch name you just pushed. Click the Compare & pull request button that is next to your branch name. You'll now see the name of your commit. In a production environment you could leave a comment about this commit. For this lab click Create pull request. GitHub verifies that the files you are adding aren't in conflict with the Master copy. If everthing checks out, and it should since these are new files, you will see a green check mark. Click Merge pull request, then Confirm merge. You'll see a "Pull request successfully merged and closed" message. At this point you can click Delete branch to clean up. You don't have to do this, but you may end up with a mess if you have too many branches. Notice that you'll have another chance to leave comments.