0% found this document useful (0 votes)
180 views38 pages

GitHub at NIT Srinagar - Veningston K - 03-06-2023

The document provides an overview of getting started with GitHub. It discusses how GitHub is a distributed version control system that allows for local and remote copies of code repositories. It then demonstrates how to set up Git on a local machine, generate an SSH key, add the key to a GitHub account, and clone a sample repository from GitHub. The document shows commands for staging, committing, and pushing changes, as well as viewing commit history and differences between versions. It emphasizes best practices for pulling changes from the remote repository before making commits.

Uploaded by

physicist sharma
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)
180 views38 pages

GitHub at NIT Srinagar - Veningston K - 03-06-2023

The document provides an overview of getting started with GitHub. It discusses how GitHub is a distributed version control system that allows for local and remote copies of code repositories. It then demonstrates how to set up Git on a local machine, generate an SSH key, add the key to a GitHub account, and clone a sample repository from GitHub. The document shows commands for staging, committing, and pushing changes, as well as viewing commit history and differences between versions. It emphasizes best practices for pulling changes from the remote repository before making commits.

Uploaded by

physicist sharma
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/ 38

Getting started with GitHub

Veningston K
Computer Science and Engineering,
NIT Srinagar
[email protected]
GitHub

Not covered in this Presentation


Computer A Computer B

Computer A

Checkout

Version database Version database


Computer B

Checkout

Version database Version database


Time Space Time Space
git add git commit
git add

git add

git commit
Demo
GitHub
Distributed Version Control System
git bash https://gitforwindows.org/
Git Profile

[email protected]

https://github.com/
https://github.com/
distributed VCS
• Local copy
remote copy Git

https://docs.github.com/en/github/authenticating-to-
github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-
ssh-agent
SSH option
• git clone
Windows
https://docs.github.com/en/github/authen
ticating-to-github/connecting-to-github-
with-ssh/generating-a-new-ssh-key-and-
abc
adding-it-to-the-ssh-agent abc

[email protected]
• This creates a new SSH key, using the provided email as
a label.
Git Bash

Windows
[email protected]
• This creates a new SSH key, using the provided
email as a label

abc
Windows
• Start the ssh-agent in the background

• Add your SSH private key to the ssh-agent.


Git Bash

Windows
https://docs.github.com/en/authentication
/connecting-to-github-with-ssh/adding-a-
new-ssh-key-to-your-github-account
ls -al ~/.ssh

• Lists the files in your .ssh directory, if they exist

• clip < ~/.ssh/id_ed25519.pub


• Copies the contents of the id_ed25519.pub file to your
clipboard
Git Bash

https://github.com/veningstonk
Settings
Git Bash

https://github.com/veningstonk
Settings
SSH and GPG keys
Git Bash

https://github.com/veningstonk
Settings
SSH and GPG keys
• Click New SSH Key
Git Bash

https://github.com/veningstonk
Settings
SSH and GPG keys
• Click New SSH Key
Key
Add SSH key
Git Bash

https://github.com/veningstonk
Settings
SSH and GPG keys
• Click New SSH Key
Key
Add SSH key
new key
Git
repository
Java
project
• Syntax
• Example
[email protected]:veningstonk/De
mo.git
Git
repository
Java
project
• Move to a local directory
• cd e:
• cd Git\ Projects/
The Demo project is cloned from
GitHub (remote repository) to a
Working Directory

Git
repository
Java
project
• Move to a local directory
• cd e:
• cd Git\ Projects/

[email protected]:veningstonk/De
mo.git
git add

git add

git commit
working
directory

• Tracked Files

• Untracked Files

• git status
The Demo project in the Working
Directory is the same as the
Remote repository
Demo.java
Sub.java Java code directory
stage unstage
git add [followed by the changes] git reset
• git add Java\ code/
• git status

The staged changes appear in green


git commit -m “add a relevant message”
• git status

This prints a summary describing the changes that we just saved


git diff [name of the file]
• git diff Java\ code/Demo.java

Deletions are printed in red,


Additions are printed in green
• git add . → it will stage all the changes that we made to the entire repository.
• git status
• git commit –m “message”
• git status
Best Practice

best practice stage


commit
git commit
History of our commits
commits
git log

Type q to exit from the Git Log


Pushing the changes made
push remote repository
git push

local copy
git pull
remote repository local repository
• Best Practice
remote repository

git pull
Pull Push
• git pull
remote repository

git push
remote repository GitHub
GitHub
delete local repository
remote repository
committed

uncommit
delete
• git reset --hard HEAD~1 → This will print a confirmation that HEAD is now pointing at the last previous commit.
• It will not be there in project history anymore. It is been deleted.
• Beware with uncommitting option.
Command Line Environment
GitHub Desktop https://desktop.github.com/
[email protected]

You might also like