or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Intermediate Git and GitHub
Assumed knowledge
In this course, we assume familiarity with the following Git commands and GitHub concepts:
add
,commit
,push
,pull
,log
If these are new to you then please join the Introduction to Git and GitHub for Beginners course, which is running in parallel.
Intermediate Git and GitHub
Joe Wallwork and Tom Meltzer
Slides: https://hackmd.io/@jwallwork/2024-07-10-intermediate-git-tools?type=slide
GitHub repo: https://github.com/Cambridge-ICCS/intermediate-git-iccs-summer-school-2024
Contents
GitHub
Navigate to the GitHub repo: https://github.com/Cambridge-ICCS/intermediate-git-iccs-summer-school-2024
Exercises
1. Branching and conflicts
Branching basics
The
main
branch is protected in our repo, meaning contributors cannot push directly to it. (More on this later.)To contribute to
main
, create a branch for your developments and open a PR when it's ready.- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →Branching basics
The
main
branch is protected in our repo, meaning contributors cannot push directly to it. (More on this later.)To contribute to
main
, create a branch for your developments and open a PR when it's ready.- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →git switch -c <branchname>
Branch-of-branch
Suppose
mybranch
adds a significant new feature. What if you spot a bug and have a fix for it?- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →develop
branchLarge codes often have a
develop
branch in addition to themain
branch.- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →Merge conflicts
What if two branches modify the same part of a file?
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →Merge conflict example
Consider the following enhancements to
equation_of_line
:#12: Implement Lagrange polynomial approach.
#13: Check that the points provided differ.
#14: Implement SymPy approach.
2. Intermediate Git commands
Checking state:
git status
Snapshot of changes staged and not staged for commit.
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Checking state:
git diff
Useful but not meant for human consumption
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →git show <branch/commit-hash>
Checking state:
git difftool
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Checking state:
git difftool
Configure by adding the following to your
~/.gitconfig
:Or run these commands:
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Configure using one of the methods above.
git switch
example-diff
git diff 2df42ae
git difftool 2df42ae
Temporary work:
git patch
I need to put aside temporary work and do some branch manipulations. How?
Temporary work:
git patch
I need to put aside temporary work and do some branch manipulations. How?
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →git apply -R my_patch.patch
Temporary work:
git patch
I need to put aside temporary work and do some branch manipulations. How?
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →svn diff > svn.patch && git apply svn.patch
git diff > git.patch && svn patch git.patch
Temporary work:
git stash
Why do I keep finding
tmp.patch
files everywhere?Stashing changes puts them on the stack.
git stash list
Editing history:
Image Not Showing
Possible Reasons
git rebase
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Some common problems:
All these things (and more) can be done with
git rebase
- one of the most powerful Git tools.Editing history:
Image Not Showing
Possible Reasons
git rebase
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →I want to change the 'base' of my branch to start at the head of another branch.
Consider the simple case of upgrading to a later version.
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →Editing history:
Image Not Showing
Possible Reasons
git rebase
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Some common problems:
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Run an interactive rebase (
git rebase -i <target>
) on branchrebase-exercise
to complete tasks 1-4.Editing history:
git reflog
Ahh, my rebase broke things! How can I reverse it?
Go back to an earlier state with (for example)
git reset --hard 3131c09
.Note that the
reset
goes in thereflog
, too!- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →The
--hard
option is potentially destructive.3. Software engineering with GitHub
GitHub: Project boards
The example repository has a Project Board for planning and tracking progress.
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Try setting up a project board for your fork.
Note: project boards are associated with users or organisations, rather than repositories.
GitHub Actions: cloud testing
From Wikipedia:
CI testing is the part that ensures the codebase is in a 'workable state'.
This was added to the example repo in #9.
GitHub: Files to always include
LICENSE
: Sets out how the code may be interacted with (e.g., can it be redistributed?)README.md
: Tells users what the repository is for and important details about its usage (e.g., installation instructions).GitHub: Settings to always use
main
branch.- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Set these up on your fork of the example repository.
Hint: https://github.com/<username>/intermediate-git-iccs-summer-school-2024/settings/branches
Debugging on GitHub Actions
Debug GitHub Actions using tmate
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →4. Tips, tricks, and fun stuff!
The following slides are for information. We might not get to them in the live course.
git bisect
: a debugging life-saverA bug was introduced somewhere in the development process, but it's unclear when. What do I do?
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →https://github.com/TomMelt/git-bisect-demo
GitHub Container Registry
For more info, please see GitHub's documentation
.gitignore
Does this
git status
look familiar to anyone?.gitignore
Ignore certain subdirectories, filename patterns, and/or extensions with a
.gitignore
file. For example:git config
Recall how we configured
git difftool
with a.gitconfig
file. We can do the same for other Git commands:Fun stuff
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →git blame
git commit -p
git log -p
git diff --name-only
git diff --word-diff
Thank you for attending!