thumbnail

Contact

Author

Med Amine TERBAH

Med Amine TERBAH

Chapter 2 : Git Tutorial

Git is a version control system that allows you to keep track of changes in your code over time. It's like a time machine for your code! With Git, you can collaborate with others, experiment with new features without worrying about breaking things, and easily roll back to a previous version if something goes wrong.

GitHub is a web-based platform that uses Git to host and manage your code repositories. It's a place where you can share your code with others, collaborate on projects, and contribute to open source software. GitHub has become the go-to platform for many developers and companies, with a thriving community of users and a wide range of tools and features.

GitLab is another web-based platform that uses Git, similar to GitHub, but with a different focus. While GitHub is more geared towards hosting public open source projects, GitLab offers a broader range of features, including the ability to host private repositories, continuous integration and deployment, and more.

Whether you choose GitHub or GitLab, or another platform altogether, the most important thing is to use version control in your development workflow. It may take some time to learn, but once you get the hang of it, you'll wonder how you ever lived without it!

-- Here is a tutorial to make and push a repository in github :

Before everything install git in your command-line : Install git

Then, Make a new directory and enter it :

mkdir learn_git_again 
$ cd learn_git_again

Make a new file "third.txt" :

echo {'>>'} third.txt

Now we go to git side and here are the steps :

  • - Initialize a git repository
  • git init
  • - Add the "third.txt" file to git
  • git add third.txt
  • - Commit what you did in a message to save it in the git tree
  • git commit -m 'Adding third.txt'
  • - Log the commits that you have, note that you will find the commit that you just did with some information
  • git log'
  • - Repeat these steps with a new file "fourth.txt"
  • echo {'>>'} fourth.txt 
    $ git add third.txt 
    $ git commit -m 'Adding fourth.txt'
  • - Now let's delete the "third.txt" file from git
  • git rm third.txt
  • - Now let's commit again but using the --amend flag which will save our changes into the last commit (so it will not create a new commit)
  • git commit --amend
Chapter 2 : Git TutorialChapter 2 : Git Tutorial

- That's it, you are ready now to push your job into a remote git repository

- But before, you need to go to Github

git branch -M main 
$ git remote add origin https://github.com/MarinosTBH/git_test.git 
$ git push -u origin main

- You should get an output like this :

git push -u origin main 
Enumerating objects: 3, done. 
Counting objects: 100% (3/3), done. 
Delta compression using up to 8 threads 
Compressing objects: 100% (2/2), done . 
Writing objects: 100% (2/2), 237 bytes | 118.00 KiB/s, done. 
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:username/repository.git
1234567..890abcd  main -> main

Flight is done for today, see you in next chapter ? Bye