You are on page 1of 5

Git and GitHub repository tutorial

1. Make sure git is installed on your system. To check open cmd and run git --version. If a
version is shown git is installed and you may proceed.

2. To create a repository on GitHub to which you wish to push(upload) the code, start by
creating a GitHub account.
3. Once your account has been created sign in and open your profile. Find the Repositories
tab. Click on New.

4. Name your repository, and choose for it to be public in order to make accessing it easier
for teachers and assistants. Click on Create repository.
5. Locally(on your PC) you can now use git to create a local git repository. First open
comand line in the folder in which your project is located. To quickly do so, open the
desired folder in windows File Explorer and type cmd into the Adress bar.
6. Start by typing git init in order to initialize the repository.

7. Create a .gitignore file. This file tells git which folders, files or file types to ignore and not
track. An example, in which the tracking of the /data folder and all .csv files is disabled, is
shown.
8. Create your jupyter notebook and type your code. Remember that git will only see
changes once you save your notebook.
9. To check the status of your repository type git status.

10. In order to push(upload) your code to the online repository, your code must first be
commited locally. First step is to add all the files you wish to commit using git add. You
can either specify a file to add or tpye * in order to add all the files present. Use git
status to check what files have been added.
11. Then to use the git commit comand in order to commit your files. The commit command
also expects a message, written after the -m option. In the example shown, the message
is „inital commit“. The message is ment to be informative in order to make the tracking
of your commits easier.

12. Next add the link to the remote repository. To do so, use the git remote add origin
command.

13. If it's the first time you're using git to push code to github, you will need to provide a
Personal access token to git. To create a personal access token, go to the github settings
page, then navigate to Developer settings. Under Developer settings, go to Personal
access tokens -> Tokens(classic) and click on Generate new token(classic). You can set the
token Expiration date, making it expirable is more secure, while making it have no
expiration date is less future work, choose wisely. Select the scope options under repo as
shown below. Leave the rest unchecked. Click on Generate token.
14. Copy the generated token. In cmd type git remote set-url origin
https://YOU_PERSONAL_ACCESS_TOKEN@github.com/<username>/<repo>.

15. Push the code to the online repository using the git push command. Type git push -u
origin main.

16. If everything was setup correctly you will see your notebook appear in the online
repository.
17. To push new changes to your files, first redo steps 10 and 11(git add and git commit) and
then do step 15(git push -u origin main).

You might also like