CodeRefinery workshops are geared towards researchers and students from different disciplines who already write some sort of code. The material is suitable for people with a wide range of technical experience, but it helps if participants have:
It is easy to create repositories in Git:
$ mkdir my-project
$ cd my-project
$ git init
This creates an empty Git repository (a directory .git
is created).
A useful Git command which should be used often is:
$ git status
It tells you the status of files in your repository, and often suggests a logical next step to do.
To make a commit, you first do the changes you want to a file, and then stage and commit it with a commit message:
# create/modify a file called my-file.txt
$ git add my-file.txt
$ git commit -m "useful commit message describing what I did"
The file my-file.txt
is now tracked by Git.
You can list all commits using the command:
$ git log
If you now do further changes to my-file.txt
, a useful command to see
how your modified file differs from the last committed version is:
$ git diff
All the Git commands above are local, and all snapshots are saved under .git
.
To store your Git repository on another server, you use remotes.
You can push changes to the remote and pull from the remote.
Remotes are used to back up your own work and to collaborate with other people.
One option to host your repository on the web is GitHub. CodeRefinery does not in any way endorse the use of GitHub, and there are many commercial and open-source alternatives, but in CodeRefinery workshops we use GitHub because you are likely to have to use it for other software anyway.
On this page choose a project name (screenshot).
For the current purposes do not select “Initialize this repository with a README”.
Once you click the green “Create repository”, you will see a page similar to:
What this means is that we have now an empty project with either an HTTPS or an SSH address: click on the HTTPS and SSH buttons to see what happens.
To push changes to the project you will either need SSH keys for the SSH
address (preferred) or you will have to use your GitHub username and password when
using the HTTPS address.
Use the second option that GitHub suggests:
… or push an existing repository from the command line
git status
.$ git remote add origin https://github.com/user/my-project.git
$ git push -u origin master
Your commits should now be online.
Here we invite you to explore and visualize an existing Git repository on GitHub.
Have a look at this example repository which contains a few commits and branches with some simple code.
7a6a2df
).fix-sum-function
was merged into the master
branch.fix-sum-function
branch. The “closes #1” string
has a special meaning since it automatically closes an issue and links together the commit and the
issue.While some of these are GitHub features, it all can be done on other sites, or by yourself without GitHub at all.