Git - Source Control Management
Concept
Imagine you have a company with several developers, all of whom are working on their own environments but on the same codebase. To avoid problems like when two people are working on the same file, we can use Git.
Git is a Source Control Management (SCM) helps all developers to work on the same application simultaneously and collaborate efficiently. You can configure project organisations and define different access levels for each group and user.
To summarise, Git is the command-line tool used to facilitate collaboration among multiple developers, and GitHub is the Git-based publicly accessible repository where you push and find your code. With GitHub, you can share your project with others along with documentation, and people can contribute to your project as well.
How to use it
If you want to transfer some files from your machine to your repository, you have to generate a classic token on your GitHub account.
- Settings / Developer Settings / Personal access tokens (classic) / Generate new token (classic)
Here are some common command-line operations for using Git on a Linux shell :
1. First of all, you need to install the Git package on your machine :
marijan# apt-get install git -y
2. Then, you need to create a folder and initialise it as a Git repository :
marijan# mkdir workplace marijan# cd workplace marijan/workplace# git init
3. Now, you can copy a repository from a source like GitHub :
marijan/workplace# git clone https://github.com/MarijanStajic/test_public.git
4. Next, you can edit or create a file in this folder and check if it is ready to be pushed :
marijan/workplace/test_public# vim hello.txt marijan/workplace/test_publicc# git status On branch main Your branch is up to date with 'origin/main'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: hello.txt no changes added to commit (use "git add" and/or "git commit -a")
5. To prepare it, you have to add this file to the staging area :
marijan/workplace/test_public# git add hello.txt
6.Before committing, you need to fill in the following information :
marijan/workplace/test_public# git config --global user.name "Marijan Stajic" marijan/workplace/test_public# git config --global user.email "marijan@stajic.me"
7. Then, you can add your commit. The commit is just to explain what you changed in the file :
marijan/workplace/test_public# git commit -m "First edit" hello.txt
8. You have to connect to the repository using the token generated at the beginning, the name of your GitHub account and the name of the repository :
marijan/workplace/test_public# git remote set-url origin https://token@github.com/MarijanStajic/test_public.git
9. Finally, you can push your file to your Git repository in the main branch :
git push origin main