Git Gists
Git
- Git basics: Git is simply a smart copy-paste tool for your project but a powerfull CLI version control tool.
- Create local and remote repo from everywhere: The script initializes Git in the directory where you run it, creates a public GitHub repository, stages and commits the local files, then pushes them to GitHub. To run it from anywhere, save it as an executable command and add its directory to your
PATH(or create a symlink). Before running it, install Git and GitHub CLI and authenticate withgh auth login. - Detached HEAD → Ghost Commit → New Branch: In detached HEAD,
HEADpoints directly to a commit rather than a branch. You can create commits there, but they won’t be attached to a branch; before switching away, preserve them withgit switch -c new-branch. If you’ve already switched, usegit reflogto find the commit and create a branch pointing to it. - Pull Request Flow – Teacher / Student: The student forks the teacher’s repository, clones that fork to local, creates a feature branch, then commits and pushes changes to their own fork. They open a pull request from that branch to the teacher’s
masterfor review and possible merging. The student does not push directly to the teacher’s repository. - How to fix a pull request conflict using GitHub’s web editor: To fix a simple pull-request conflict in GitHub’s web editor, open the PR, click Resolve conflicts, edit the conflicting file to keep or combine the desired code, remove all conflict markers, then mark it resolved and commit the resolution. Resolve the conflict by choosing the final code—not by assuming one author’s changes should automatically win. In this example, José’s
DataSeederchanges were kept, but his newwhileimplementation was not, so the mergedmasterretained the old loop. “Current” refers to the PR’s target branch (master); “Incoming” refers to the PR’s source branch. docs.github - Authomate Sync to Local: To automate syncing, first update the fork on GitHub with
gh repo sync, then pull that branch into your local clone. A script can run both steps on a schedule (for example, hourly via cron) or after detecting upstream changes through API polling or a webhook. Use the same branch name throughout: the example mixesmasterandmain, which may cause the pull to fail. Also, don’t expose an unauthenticated webhook that runs shell commands; verify GitHub’s webhook signature and validate the event before syncing. GitHub CLI supports syncing a fork from its parent or another repository. docs.github
评论
?
参与讨论