17. Git Github I dalis - MantsSk/CA_PTUA14 GitHub Wiki

Version control systems

What are they?

Put it simply - it is software that allows you to version your code while working on it with as many people as you wish.

During the course we will be using the most popular - GitHub. Download git bash: link

What can we achieve with git? 🗺️

So what does the versioning mean? At any given time we can save current state of our code base, upload it, go back to any previous version of our project, we can revert it into any stage and download any changes made by our colleagues. All the information is beautifully stored on github. Also modern VSC systems like Github or Gitlab (and others) allow us to also seamlessly deploy, test and do other important things with our codebase.

Setting up git 🧰

Open git bash if you are using windows or any terminal on other OS:

Setup your name:

git config --global user.name "name surname"

Setup email:

git config --global user.email [email protected]

Check settings:

git config --list

Connecting with ssh key.

Open terminal to generate ssh key and enter this command:

ssh-keygen -t rsa -b 4096 -C "[email protected]"

Don't type anything and just press "Enter" a few times. If you are re-genearting the key it will ask your permission to overwrite (press Y).

You will see key getting generated:

Enter file in which to save the key (C:\Users\mantasskara/.ssh/id_rsa):
C:\Users\mantasskara/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\mantasskara/.ssh/id_rsa
Your public key has been saved in C:\Users\mantasskara/.ssh/id_rsa.pub
The key fingerprint is:
...

You can copy the key directly from terminal with these commands (change to your path):

Windows - type C:\Users\mantasskara/.ssh/id_rsa.pub Mac/Linux - cat ~/.ssh/id_rsa.pub

Copy the value you see after this command. Should be something like this:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3LHCcnuUun3fvzLbDBRyYKHsKilWvA2MvWMuSL0CzMWxkw+0yRpV/N8fysEKYcRus/Uq58R9vRU2hY4P3kH3iU8cziT5Zj0Qc9k8KY+CwrJfdzgTojg5TO3ujTTq7qfvjR58EM/MnJrfGrsq+sfnq9ltpumX7Vq0Zk6IhnuA+5BLnY3bd1+7NXw7S4VHH+PN7EDoyjbLuqLuGJRU2dRgFTpRYRYdF4LpDa5vA/kDbnJJ5NUXHCJeLs/3Z2vc9Efcq/Ybz8A/4ZC9npGOJnSYYMrRSiCmJ1CWhduC6t4HFp3qIg2C7x7PJeaHm7XE3mOTFQSLgE9uOJ [email protected]

Go towww.github.com on top right click on your profile -> settings -> SSH and GPG keys -> New SSH key.

Give the key a name of your choice and paste the key. Click Add SSH Key.

Create an empty GITHUB repository

Open www.github.com. Login and hit Start a project. Give it a name and click create repository.

Lets link your PyCharm Project with your created GitHub repository

Open your PyCharm (or VSCode) IDE and open your existing project where you store your code from classes (or create a new one)

Initiate git project by typing in the PyCharm (or VSCode) terminal:

git init (only needed once per project)

Link with the project that you created on github.com. I created "Test4":

git remote add origin [email protected]:MantsSk/Test4.git (only needed once per project)

Now you can check git status once again:

git status

To start tracking all files simply:

git add .
git commit -m "My first commit!"

Check branch name:

git branch

Now we have to 'push' it to remote:

git push origin <branch_name>

Congratulations you have now successfully tracked the changes and they are also visible on Github! Check them out!

Exercise:

  • Create a new repository named "OOP_PTUA14_EXERCISES" on github.com
  • Open your test code from OOP Lesson with PyCharm/VSCode
  • Add it to github by following instructions above
  • Send the repository to Mantas Skara

🌐 Extra reading/watching: