L03_Git and Github¶
Goal¶
Create your personal webpage
How to generate a game development idea :
Create “Bunny Hop” in 20 Minutes
Bunny Hop Project >Bunny Hop
Installation¶
- Go to
Self Service
- search and install
Pycharm
andVisual Studio Code
How to Download Student Template and push your Own Repo to Github¶
Download Student Template¶
1 Make sure you’ve registerd on Github, remember your account and password. (2FA) See here to create your personal website repo on Github.
2 Download the StudentTemplate_HTML by ‘Code’ - ‘Download as ZIP’
3 Edit your webpages by any texteditor your like, you can use Visual Studio. See L02_EditYourWebPage
4 For the initial commit/first commit to push the local repository to the remote repository(Github), you can initialize the local project as a git project.
-
Initialize Git repository First, you need to initialize a Git repository in your project folder. Make sure you are in the project folder and run the following command:
git init
This will create a .git folder in the current directory, identifying this as a Git repository.
-
Add files to the repository Add your project files to the Git staging area:
git add .
-
Commit changes Commit these files to the Git repository:
git commit -m "Initial commit"
-
Add remote repository address Now you need to link your remote GitHub repository to this local repository. Use the following command to add the remote repository:
git remote add origin https://github.com/your-username/your-repo.git
Replace your-username and your-repo with your GitHub username and repository name.
-
Push to remote repository Push your changes to GitHub:
git push -u origin main
Tips: before you push your repor,
- Check the remote branch name If you want to confirm whether the remote repository’s branch is main or master, you can use the following command to view the remote branch:
git branch -r
This will display a list of branches in the remote repository. If the remote branch is main instead of master, you can rename the local branch to main and push it:git branch -m master main
git push --set-upstream origin main
Hints: When you run the git push command, Git attempts to authenticate you with GitHub to push your changes. This is why you’re being prompted to sign in. In this case, just open with broswer and type your password to fufill the Authentication.
After that, you could foucus on your local repo editing, and when you need to push your repo to Github, just run the terminal within the project folder:
git add <file>
git commit -m "message"
git push
Create your personal website repo on Github¶
New - Enter your repo name - Create repository
You can use these following command.
To publish your site¶
-
Configure: Settings - Pages - Source - GitHub Actions
-
Edit repository details
Configure a publishing source for your github pages site
- Done
Useful Video¶
How to Host a Website On Github Pages
Refference - Issues & Solutions¶
Resove Merge Conflict¶
Here’s how you can resolve the conflicts:
- View the Conflict Markers Each file with conflicts (e.g., 404.html, about.html, etc.) will contain conflict markers that look like this:
These markers indicate the conflicting changes between your local repository (above =======) and the remote repository (below =======). (Just keep the text you want and delete text/content that you don’t need,)
After deciding, edit the file to remove the conflict markers (<<<<<<<, =======, and >>>>>>>), and keep only the desired content.
### Resolve the “pack exceeds maximum allowed size” issue
- Revert the commit and remove the large file If you suspect this or another file is causing the issue, you can revert the commit and remove the file. Here’s how to roll back:
git reset HEAD~N
(N stands for a number)
This will undo the last N commit and move its changes back to the staging area.
- Check the current git status
git status
- Add files manually in oder on by one (make sure this time the number of files you add is expected to be no more than 10M)
git add <file>
git push
git status
again to check the remained files, repeat steps 2~5 untill you successfully git push all files to your remote repo.