Using Git and GitHub
We will use GitHub and Git to submit some homeworks.
Full reference on Git is available here.
Installing Git
- For Windows users: download and install Git. Run Git Bash.
- For Linux users: run command
sudo apt install gitin Terminal (typically it is already installed).
Generating SSH Keys
Run the ssh-keygen command in the console, to generate SSH keys.
Specify the passphrase for the keys. The keys will be generated in the following folders.
- MacOS:
/Users/andrew/.ssh - Windows:
/c/Users/andrew/.ssh - Linux:
/home/andrewt/.ssh
id_rsa is a private key, id_rsa.pub is a public key.
Creating Repository
-
Login into GitHub or create an account.
-
Add your public SHH key to your account.
-
Create a new private repository. Name it
<group>_<surname>, e.g.231_tatarnikov. If there is another student with the same surname, add suffix_<n>(nis the first letter of the name). -
Add the workshop instructor and the teaching assistant as collaborators to the project. Here is an example of a link to do this (Project > Setting > Manage Access):
https://github.com/<your account>/<your project>/settings/access.
Working with Repository
- Clone the created repository to your machine:
git clone https://github.com/andrewt0301/test.git - The repository will be cloned in the
testfolder. Change the current directory to it:cd test - See help of using Git:
git help - Set your user name and email for this repository:
git config user.name Andrei Tatarnikov git config user.email andrewt0301@gmail.com -
Create or copy the
hello.cprogram to this folder. - Check the status of files in the Git repository:
git status - Add the
hello.cfile to the commit:git add hello.c - Send the commit to the repository:
git commit -s -m "hello.c is added" - Update the remote repository (GitHub):
git push origin main - Get changes from the remote repository (GitHub):
git pull