Lesson 07: Git Github (Part 1) - CodeAcademy-Online/python-level-1 GitHub Wiki
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
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.
Open git bash if you are using windows or any terminal on other OS:
git config --global user.name "name surname"
git config --global user.email [email protected]
git config --list
Open git bash terminal to generate ssh
key:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Open file id_rsa.pub
with any text editor and copy it.
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
.
Open www.github.com. Login and hit Start a project
. Give it a name and click create repository
.
Open up terminal:
git clone repository
Create a file and check what can git say about the file:
git status
Tell git to start tracking changes within the file:
git add <filename>
Check status once again:
git status
What is the different this time?
Now we need to create a commit, which is simply a point in history of your project showing what was changed and who and when did the change. Let's create it:
git commit -m "first commit"
.
Check status once again:
git status
.
We are ready to push
now:
git push
or better git push origin <branch_name>
Congratulations you have now successfully tracked the changes and they are also visible on Github
! Check them out!
What if you already had a codebase and now suddenly you want to start tracking it? Not a problem.
Initiate git project in the directory of your choice:
git init
Now you can check git status once again:
git status
To start tracking all files simply:
git add .
git commit -m "initial commit"
And just like that you now have a repository
that is being tracked.
Now we have to 'push' it to remote:
git push origin <branch_name>
So far we've seen how to create a project but how do we join an already existing one.
It's simple go to projects Github
page. Click on green button saying Code choose the way you want to acquire a copy -> ssh/ hhtp
.
Open up the terminal, go to the place where you want to clone the project and then clone it:
git clone <link_to_project>
Now you have acquired a copy of codebase to your computer. Be careful, because is not being updated automatically. To grab the latest changes we need to do:
git pull
.
This simply tells git
to pull
latest changes from remote repository (Github
). Note that the command is similar to git push
but does the exact opposite - it updates the local copy of codebase.
.gitignore
is a configuration file used in Git
to specify which files and directories should be ignored by the version control system. This is useful for excluding files that don't belong in the repository, such as compiled binaries, temporary files, or sensitive information like passwords.
The file is named .gitignore
, and it should be placed in the root
directory of your Git
repository.
Example:
# Ignore compiled binaries
*.exe
*.o
*.out
# Ignore log files
*.log
# Ignore virtual environment directories (for Python projects)
venv/
__pycache__/
# Ignore compiled bytecode files (for Python projects)
*.pyc
*.pyo
__pycache__/
# Ignore database files
*.db
*.sqlite
# Ignore editor/IDE-specific files and directories
.vscode/
.idea/
# Ignore environment configuration files with sensitive information
.env
A README.md
file is a plain text or markdown file commonly found in software projects and repositories. Its primary purpose is to provide essential information about the project, making it easier for users, collaborators, or visitors to understand and use the project. It often serves as the project's documentation, giving an overview of what the project is, how to use it, and other relevant details.
Example:
# My Simple Project
## Overview
My Simple Project is a basic web application that demonstrates a few key features.
## Installation
1. Clone the repository:
```bash
git clone https://github.com/yourusername/simple-project.git
- Create a new
github
repository and upload dummy code. Test all the commands you have learned today. - We advice with every new lecture create a new
github
repository and store code there.