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
GitHub
Wojciech Hardy
link: https://hackmd.io/@WHardy/RR25-git3
Let's take a look at GitHub
github.com
Notably, it's not only GitHub
GitHub - think: Microsoft, tons of repositories managed remotely, mostly for open repositories.
GitLab - think: DevOps and CI/CD.
(But people list various differences)
Atlassian's BitBucket - think: private firm solutions and Jira.
Etc. We'll use GitHub as an example.
Working with GitHub
There's several ways you can interact with GitHub. Let's cover a few cases:
Happy Git With R has nice step-by-step guides - not only about R and GitHub. Check it out.
Password, authentication, etc.
We might have to go through some connection issues on our first go. Here's a good reference.
In principle, Git might ask you for authentication when you first connect with GitHub from your computer. It might be enough to log in via browser (depends on git version).
But if it asks for username and password, note that the 'password' might refer to a Personal Access Token.
How to generate one?
On GitHub, go: Account settings -> Developer settings -> Personal Access Tokens -> Generate new token.
Check
user
,workflow
andrepo
and it should cover most basic usage. Copy the token and place it in the prompt instead of the password.Case 1. GitHub to local
Click the
button at GitHub.
Let's start with a
Readme.md
file (check the relevant box).This will initiate a non-empty repository.
At your Repository, click the green code button and copy the HTTPS URL.
Example:

mkdir repositories
cd repositories
git clone <copied_url>
(e.g.:
cd MyRepoName
ls
git status
head README.md
git remote show origin
)
.txt
file. Stage it, commit it, put it back in the remote repository.echo "some text" > hello.txt
git add hello.txt
git commit -m "Added a hello.txt file"
git push
Note: this might be the moment when you run into an authentication request.
Refresh the page. Your hello.txt file should appear.
Case 2. Local to GitHub
cd ..
mkdir Ex2Repo
cd Ex2Repo
git init
.txt
file. Stage it and commit it.echo "some text" > hello.txt
git add hello.txt
git commit -m "Added a hello.txt file"
Click the
button at GitHub.
Don't start with any of the standard files! You will then initiate a repository without a commit history (avoidng a conflict of two unrelated commit histories).
At your bare repository, click the green code button and copy the HTTPS URL.
Example:

git remote add origin <copied_url>
git branch -M main
will rename themaster
branch tomain
git push -u origin main
Note: you have to set the upstream for your branch (you can also do it with --set-upstream)
Case 3. Forking and getting updates
Example (press the "Fork" button):

Repeat Case 1 steps for your new repository.
In your local repository create a new file, stage it, commit it and push it.
In GitHub you should see you're '1 commit ahead'. Try opening a pull request (you don't need to follow through).
We need to establish a link:
a) Check the configured remote repo.
git remote -v
b) Add a path to the forked remote repo.
git remote add newUpstream <copied_url>
c) Check again.
git remote -v
git fetch newUpstream
git merge newUpstream/main
Case 4. Using e.g. GitHub for Desktop
(it's just clicking on names you already know).
Case 5. Using GitHub with RStudio
File -> New project… -> Version control -> Git
You should now have a "Git" tab in top-right corner. Check it out.
You can use the terminal the same way you used Bash.
ASSIGNMENT
hello.txt
file inside (e.g. write the date inside, or whatever you want to).That's it. That's the assignment.
Contributing to another repository
Sometimes you'll want the owner of the original repository to include your changes. E.g.:
Go to your forked repository. You should see the information that you're ahead of the repository that you forked.
ASSIGNMENT: Initiating a pull request
In your repository you can grab the changes from its source. But you can also try to pass your commits to it.
You can do so through the pull requests tab or by clicking the
contribute
button.Do it now with the course repository.