Git / Github
🔥

Git / Github

Tags
Git
Github
Published
December 21, 2022
Author
Oussama Belhadi

What’s Git?

Git is a DevOps tool used for source code management. It is a free and open-source version control system used to handle small to very large projects efficiently. Git is used to tracking changes in the source code, enabling multiple developers to work together on non-linear development. Linus Torvalds created Git in 2005 for the development of the Linux kernel.
 

How things Work when you’re dealing with a remote Repo, or working on a collaboratif project.

notion image
 
 

How things work locally :

notion image
First thing first you will have to set up a git repo on your project
1- First check if you have Git insalled : git -v
2- git init (initializing a git respository inside ur project)
3- git status (To check waht's going on in ur project, can only be used in a git repository)
  • Master / Main : is the default branche, it contains the main branche
  • the respository is local and not linked to any external server or host
// Configuring Git
  • The first step is u should get identified by ur name and email so if u make a change it's will be trackable so in a collaborative environement if u changed something it's will be shown ass "Made by (YourName + email)" so if someone want more details they could ask u
1- git config --global user.name "Oussama" 2- git config --global user.email "test@gmail.com"
//Creating first Commit
1- git commit (it returns on which branche we are + if there's something to commit)
  • untracked files are not ready to be tracked, in order to commit a file u need to add it first
2- git add test.txt (we prepared the file to be tracked)
there's 2 steps to commit :
1- which files we want to add into the staging area
git add filename.extension [we can chain files together]
2 - from the staging area we commit
git commit -m "commit message"
3- to know the history of our commits we could use :
git log
 
4- we can go back from a specific commit git checkout commithashnumber
when we go back to another version of our code we quite the master branch and go to a header place
5- git branch : lists the available branches git branch branch-name : creating a new branche
6 - you can switch between the branches however u like git checkout available_name_branch
7- to merge the changes of a branch in another branch we use : git merge secondBranche
 
8 - After that you could simply use the git push command, An Authentification window window will pop up on, after you Register/Login, you can initialize the remote repo and start making changes on your local repo and pushing them regularly to the remote repo.
 
 
More to learn : Master the essentials and the tricky bits: rebasing, squashing, stashing, reflogs, blobs, trees, & more!