Workshop 2022-03-30 Getting Started With Git and GitHub
Workshop 2022-03-30 Getting Started With Git and GitHub
ALTERNATIVES • SourceForge
• Google Cloud Source Repositories
TO GITHUB • Phabricator
• Gitea (self-hosted)
• Apache Allura
• Launchpad (by Canonical, distributors of Ubuntu
Linux)
• Ref: https://www.geeksforgeeks.org/top-10-
github-alternatives-that-you-can-consider
SIGN UP FOR A
GITHUB ACCOUNT
https://education.github.com/disco
unt_requests/student_application
SSH KEYS
https://docs.github.com/en/authent
ication/connecting-to-github-with-
ssh
• Allows passwordless connection with GitHub
• Generate key:
• ssh-keygen -t ed25519 -C
[email protected]
• DO NOT USE AN EMPTY PASSPHRASE
• Start the SSH agent:
• eval "$(ssh-agent -s)"
CREATE A NEW
REPO • Click the “New” button
• Create a new repo at GitHub
• On your PC, move existing code directory to a
IMPORT different name, e.g. myproject_orig
CONFIGURATION
user.email [email protected]
• git config --global core.editor nano
• Alternatively, change your environment
variable VISUAL and/or EDITOR to
“nano” or whatever editor you prefer
• git config --global init.defaultbranch main
• Copy the “ssh” repo link
• In terminal:
• git clone [email protected]:myname/myrepo
CLONE THE
REPO
• Each circle represents a “commit”
DIAGRAM OF
STATE OF
CODE
• Type (or use editor of choice):
• nano hello.py
• Edit
• Save
CREATE A NEW
FILE Contents of file:
#!/usr/bin/env python3
print("hello, world!")
ADD/STAGE • Type:
THE FILE • git add hello.py
• Type:
• git commit
• An editor will launch asking for a commit
message
• Type a brief description of the changes you
CHANGE editor
• N.B. you are committing this change to your
local repository
• Check the repo on GitHub
• Notice that the file is not there
• DEMO
• Type
PUSH THE • git push –u
BASIC BRANCH
• Create a new branch and switch to it
• Work on new branch
AND MERGE •
•
Compare with main branch
Commit new branch
• Merge new branch into main
• git checkout -b new-feature
• List all branches
• git branch
• Edit new file goodbye.py
• git add goodbye.py
• git commit
WHAT GITHUB
owner of the repo pull the change into the
originating repo
INTEGRATED •
•
Tracing
Version control
DEVELOPMENT • Editors now have some IDE features (see
ENVIRONMENTS previous slide)
• E.g.
(IDES) • Eclipse https://www.eclipse.org/ide/
• NetBeans https://netbeans.apache.org/downloa
d/index.html
• macOS XCode
• Using a separate Git/GitHub application or
command line is a little annoying
• Switch from editing to GH Desktop or terminal to
perform Git operations
EDITOR • Editors for programming almost all have
INTEGRATION integration with Git and GitHub
• Indicators while editing to show state of code
• Perform git operations: add/stage, commit, push,
tag, etc.
• Perform GitHub operations: refer to an issue, etc.
• VisualStudio Code
• Download: https://code.visualstudio.com/
• Free of charge editor from Microsoft
• Runs on Windows, macOS, and Linux
REFERENCES