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.
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.
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
and repo
and it should cover most basic usage. Copy the token and place it in the prompt instead of the password.
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.
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 the master
branch to main
git push -u origin main
Note: you have to set the upstream for your branch (you can also do it with --set-upstream)
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
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.
hello.txt
file inside (e.g. write the date inside, or whatever you want to).That's it. That's the assignment.
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.
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.