Basic of Git & GitHub
Lecture
1
CMSC 320�
INTRODUCTION TO �DATA SCIENCE
– FARDINA FATHMIUL ALAM
(fardina@umd.edu)
�
2024
RECAP: Importance
2
These skills are essential for effective data analysis, collaboration, and handling data in real-world projects.
Git
3
Version Control System (VCS)
A software tool used by developers to manage changes to source code over time.
Git is the most popular version control system in the world.
4
VCS Types
5
There is a single “central” copy of your project somewhere (probably on a server), and programmers will “commit” their changes to this central copy directly.
Each programmer has a full project copy on their local machine. They commit changes locally and use push and pull operations to sync with a shared server for collaboration.
Git
Git is a version control system that helps developers manage and track changes in their code. It's like a time machine for your code, allowing you to go back to previous versions if something goes wrong or if you need to see how your code looked at a certain point in time.
6
Git
A distributed version control system , used by most major corporations and labs
7
Why Git?
8
Installing Git
9
Git Repository
After installing Git, you can initialize it for a project to create a new Git repository.
The Git Repository, represented by the '.git' directory, is a database that contains all the project source code and the history of all code updates. The '.git' directory is typically located at the root of the project directory.
10
Git Repository
While a Git repository can be stored on your local machine, especially for solo projects, it's common practice to store project code in a repository on a remote server.
11
Github
GitHub is a web-based platform that serves as a hosting service for Git repositories.
12
Git Commands
13
Git Command
14
command | description |
git clone url [dir] | copy a git repository so you can add to it |
git add files | adds file contents to the staging area |
git commit | records a snapshot of the staging area |
git status | view the status of your files in the working directory and staging area |
git diff | shows diff of what is staged and what is modified but unstaged |
git help [command] | get help info about a particular command |
git pull | fetch from a remote repo and try to merge into the current branch |
git push | push your new branches and data to a remote repository |
others: init, reset, branch, checkout, merge, log, tag | |
To start a new project with Git
We can either
15
Git init
Initialize a new repository:
Git init creates an empty git repository for project tracking. Once the repository is created, any files added to the repository are automatically tracked.
command:
16
Git Clone
17
Git Clone
18
Adding a file to git repository: git add, commit
19
git init command is used to initialize a new Git repository in a directory.
→ shows which files have been changed and need to be committed to the repository.
Adding a file to git repository: git add, commit
20
Step 1: Staging telling Git to include this file in the next commit.
Step 2: Commit committed those changes with a message
Adding Files to Git
Staging is the process of organizing and preparing our project files for a commit. It is the intermediate step between modifying our files and storing them permanently in the repository.
Git Staging Area
The staging area in Git is an intermediate area where changes are prepared before they are committed to the repository.
21
Git Branch
22
Show all the branches that exist in the rep
* 🡪 Current Branch
We can use the git branch command to
Git Branch
23
* 🡪 Current Branch
Create a new branch�
We start with a repository, create our branch, make changes on our branch, and when we're finished, we merge those changes into the "main" branch. We ensure everything works together and then upload it back to GitHub.
Delete an existing branch:
git branch -d <branch name>
Git Checkout
24
REMEMBER:
Switch between branches in a repository.
Git Push
25
Upload / push your local Git commits to a remote repository, such as one hosted on a platform like GitHub.
$ git push origin-main local-master
$ git pull <remote-repo-url>
Git Pull
Refers to refers to fetching changes from a remote repository. Download and update our local repository with the changes made to the remote repository. First fetch the changes and then merge them into the working branch.
Git Overall
26
A Basic Git Workflow
27