Skip to content

Commit b95ecd5

Browse files
Merge pull request #48 from dtxe/main
GH Actions, Git Cheatsheet, Naming
2 parents 62fd113 + 0d805de commit b95ecd5

File tree

6 files changed

+210
-19
lines changed

6 files changed

+210
-19
lines changed

.github/workflows/automatic_pr_comment.yaml

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
1-
name: Automatic PR Comment
1+
name: UofT-DSI Main Repository PR Workflow
22

33
on:
44
pull_request_target:
55
types: [opened, synchronize]
66

77
jobs:
8-
comment:
8+
handle-pr:
9+
if: github.repository_owner == 'UofT-DSI'
910
runs-on: ubuntu-latest
1011
steps:
11-
- name: Comment on PR
12+
- name: Handle PR based on source branch
1213
uses: actions/github-script@v6
1314
with:
1415
script: |
15-
const issue_number = context.payload.pull_request.number;
16+
const pr = context.payload.pull_request;
17+
const branchName = pr.head.ref;
18+
const issue_number = pr.number;
1619
const repo = context.repo;
17-
const commentBody = `Hello, thank you for your contribution. If you are a participant, please close this pull request and open it in your own forked repository instead of here. Please read the instructions on your onboarding [Assignment Submission Guide](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md) more carefully. If you are not a participant, please give us up to 72 hours to review your PR. Alternatively, you can reach out to us directly to expedite the review process.`;
18-
// Check if the PR is made to a repo in the UofT-DSI organization
19-
if (repo.owner === 'UofT-DSI') {
20-
github.rest.issues.createComment({
20+
21+
if (branchName.startsWith('assignment')) {
22+
const commentBody = `This pull request was made to the wrong repository. Please open it in your own fork instead. Refer to the [Assignment Submission Guide](https://github.com/UofT-DSI/onboarding/blob/main/onboarding_documents/submissions.md) for detailed instructions.`;
23+
24+
// Comment on the PR
25+
await github.rest.issues.createComment({
26+
owner: repo.owner,
27+
repo: repo.repo,
28+
issue_number: issue_number,
29+
body: commentBody
30+
});
31+
32+
// Close the PR
33+
await github.rest.pulls.update({
34+
owner: repo.owner,
35+
repo: repo.repo,
36+
pull_number: issue_number,
37+
state: "closed"
38+
});
39+
} else {
40+
const commentBody = `Thanks for your contribution! 🎉\n\nPlease remember to tag or request a review from the DSI team. Give us up to 72 hours to review your pull request. We appreciate your patience and efforts.`;
41+
42+
await github.rest.issues.createComment({
2143
owner: repo.owner,
2244
repo: repo.repo,
2345
issue_number: issue_number,
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ jobs:
3636
- name: Upload artifact
3737
uses: actions/upload-pages-artifact@v3
3838
with:
39-
# Upload entire repository
4039
path: './03_instructional_team/githubpages'
4140
- name: Deploy to GitHub Pages
4241
id: deployment

02_activities/practice/git_advanced.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Git Advanced Homework
2-
3-
**Note**: Homework problems are not assessed and are provided for your own personal practice. Feel free to discuss these with your peers and learning support during work sessions!
1+
# Git Advanced Practice Problems
42

53
## Tasks
64
The `dtxe/DSI_git_assignment` repository contains a short Python script that

02_activities/practice/git_moderate.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Git Basics
2-
3-
**Note**: Homework problems are not assessed and are provided for your own personal practice. Feel free to discuss these with your peers and learning support during work sessions!
1+
# Git Moderate Practice Problems
42

53
## Tasks
64
### Task 1
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# 🧠 Git Commands Cheatsheet (with Inline Comments)
2+
3+
## 🔧 Configuration
4+
5+
```bash
6+
git --help # Show overview of Git commands
7+
git config --global user.name "Simeon" # Set your Git username globally
8+
git config --global user.email "[email protected]" # Set your Git email globally
9+
git config list --global # List global Git configuration settings
10+
git config --global core.editor "code --wait" # Set VS Code as default Git editor
11+
```
12+
13+
---
14+
15+
## 🔑 Credential Manager
16+
17+
```bash
18+
git credential-manager github list # List GitHub credentials currently used
19+
git credential-manager github login # Authenticate and store GitHub credentials
20+
```
21+
22+
---
23+
24+
## 📁 Repositories
25+
26+
```bash
27+
git init # Initialize a new Git repository in the current folder
28+
git init -b main # Initialize with 'main' as the default branch
29+
30+
git clone <repository_url> # Clone an existing repository
31+
git clone <repository_url> <new_dir> # Clone and rename the directory
32+
```
33+
34+
---
35+
36+
## 📝 Tracking Files
37+
38+
```bash
39+
git status # Show current changes and staging info
40+
touch README.md # Create a new file named README.md
41+
git add <file_name> # Stage a specific file
42+
git add -A # Stage all modified and new files
43+
```
44+
45+
---
46+
47+
## ✅ Committing
48+
49+
```bash
50+
git commit -m "Your message" # Commit staged changes with a short message
51+
git commit # Open editor to write a full commit message
52+
```
53+
54+
---
55+
56+
## 🌐 Remotes
57+
58+
```bash
59+
git remote -v # View remote repository URLs
60+
git remote add origin <url> # Add a remote named 'origin'
61+
git remote show origin # Show detailed info about 'origin'
62+
git remote add upstream <url> # Add a remote for upstream (main project repo)
63+
git remote rm origin # Remove a remote called 'origin'
64+
```
65+
66+
---
67+
68+
## 🔁 Syncing Changes
69+
70+
```bash
71+
git fetch origin # Download latest changes from 'origin' (no merge)
72+
git pull origin <branch> # Fetch + merge updates from a remote branch
73+
git pull --no-rebase origin <branch> # Fetch + merge without rebasing to preserve the commit history
74+
git pull upstream main # Pull latest changes from upstream main branch
75+
git push origin <branch> # Push your local branch to 'origin'
76+
git push -u origin main # Push and set upstream tracking for main
77+
```
78+
79+
---
80+
81+
## 🌿 Branching
82+
83+
`git branch` performs branch admin tasks (eg. list, delete)
84+
`git switch` switches your current working directory to different branches
85+
86+
Git provides multiple ways to perform similar actions, and your choice of command strategy will end up being a mix of personal preference and standard practices in your team.
87+
88+
```bash
89+
git branch -v # List all local branches with last commit
90+
git branch -a # List all branches (local + remote)
91+
git branch <branch_name> # Create a new branch from the current commit
92+
git branch -d <branch_name> # Delete a local branch
93+
94+
git switch <branch_name> # Switch to an existing branch
95+
git switch -c <branch_name> # Create a new branch from the current commit and switch to it
96+
git switch -c <branch_name> <commit_id> # Create a new branch from a specified commit and switch to it
97+
```
98+
99+
---
100+
101+
## 🔄 Merging & Conflicts
102+
103+
```bash
104+
git merge <branch_name> # Merge specified branch into current one
105+
# If conflicts occur:
106+
# <<<<<<<, =======, >>>>>>> markers will show in affected files
107+
# Manually edit and fix conflicts, then:
108+
git add <file_name> # Stage the resolved file
109+
git commit # Commit the merge resolution
110+
```
111+
112+
---
113+
114+
## 🚀 Branching Workflow
115+
116+
```bash
117+
git switch -c feature-branch # Create and switch to a new branch
118+
# Make code changes
119+
git add -A # Stage all new and modified files
120+
git commit -m "Feature updates" # Commit with a clear message
121+
git push origin feature-branch # Push new branch to remote
122+
```
123+
124+
---
125+
126+
## 📤 Uploading Changes to GitHub
127+
128+
**Initial Setup:**
129+
```bash
130+
# Fork the repo on GitHub
131+
git clone <repo_url> # Clone forked repo to local
132+
```
133+
134+
**Making Changes:**
135+
```bash
136+
git switch -c <new_branch> # Create and switch to a feature branch
137+
# Edit files
138+
git status # Check what's modified
139+
git add -A # Stage all changes
140+
git commit # Commit changes
141+
git push origin <branch> # Push feature branch to GitHub
142+
```
143+
144+
---
145+
146+
## ❌ Undoing Mistakes
147+
148+
### 🔄 Accidental PR Merge
149+
150+
> On GitHub:
151+
1. Click **"Revert"** on the merged PR
152+
2. Merge the auto-created `revert-1-<branch>` PR
153+
3. Click "Revert" again on the revert-PR
154+
4. Leave the final "revert of a revert" PR open as the actual submission
155+
156+
157+
### ⛔ Undoing an accidental push to GitHub
158+
159+
**⚠️ The commands shown here should be used with caution.**
160+
161+
#### Important caveats
162+
* Generally, anything uploaded to the internet should be considered to have been made public permanently.
163+
* If you accidentally uploaded a password or other credentials, those should be revoked immediately.
164+
* It is considered bad practice to change Git history. These commands should only be used in very specific circumstances.
165+
166+
#### Steps
167+
* Optionally, backup your current latest commit that was accidentally pushed
168+
* `git switch -c backup-branch`
169+
* Ensure your local branch is at the correct commit that should be uploaded
170+
* Use `git log` to find the commit ID you want to revert a branch to
171+
* Revert your local branch to the correct commit
172+
* `git switch -C [branch name] [commit id]` to overwrite the branch, and set it to the specified commit ID
173+
* Overwrite the GitHub repository with the updated branch
174+
* `git push origin [branch name] --force`

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ Assignments are typically due on the Sunday following the module's live learning
4949
**Questions can be submitted to the _#dc-help_ channel on Slack**
5050

5151
* Technical Facilitator:
52-
* **Simeon Wong**
52+
* **Simeon Wong**
5353
5454

5555
* Learning Support Staff:
56-
* **Dmytro Bonislavskyi**
56+
* **Dmytro Bonislavskyi**
5757
58-
* **Laura MacKew**
58+
* **Laura MacKew**
5959
60-
* **Moniz Chan**
60+
* **Moniz Chan**
6161
6262

6363

0 commit comments

Comments
 (0)