Git Basics
Content
1. What is Git and what is it for?
What is Git for, and what is a version control system anyway? A version control system is a system that records changes to a file or set of files over time and allows you to revert to a specific version later. Simply put, in case of a file change, the file and the place of the change will be marked, you can also undo the previously entered file changes, see who last changed something and caused the problem and when, and much more. If you break something or lose files, you can easily fix it.
One such system is Git. At the moment, it is the most common for a number of reasons:
- Free and open source
- Fast
- Simple branching
- Backup
Hostings are provided for git repositories, for example: GitHub, Codebase, Bitbucket, GitLab, etc.
2. Basic commands:
Command | Command description |
---|---|
git init | creating a new repository |
git status | view status of current files |
git add | adding changes and new files to the current directory |
git add file.py | adding file.py |
git .add | adding all changes |
git commit | creating a new commit |
git commit -m ’text' | creating a commit called text |
git branch | shows a list of all branches |
git branch -v | shows a list of branches and the latest commit in each |
git branch name | creates a new branch name |
git branch -D name | deletes a branch name |
git checkout | switching between recent commits |
git checkout file | revert file to last commit state |
git config | configuration and options git |
git config –global user.name | shows username |
git config –global user.name ‘New name’ | changes username |
git config –global user.email | shows the user’s email |
git config –global user.email ’name@gmail.com' | changes the user’s email |
git push | uploading local commits to a remote repository |
git pull | downloads changes from the remote repository to the local one |
git clone | cloning a project from a remote repository |
3. Dictionary
Branch
A branch or copy of the project where you can make any changes, they will not affect the main project.
Git
How files and their versions are stored.
Cloning
Copying a repository to a hard drive.
Commit
Set with changes (changed, new and added files) written to the local repository.
Push
Sending changes to the server.