Tutorial Git

Summary:

  • git init
  • git status
  • git add .
  • git status
  • git commit -m “version 1.0”
  • git status
  • git log

*If you delete some files and need to go back in time, just type

  • git checkout

Detailed Explanation:

Git is version control software.

Mainly, as a programmer, it gives you two big benefits which allow you to:

#1.- Work Productively (Alone or in a Team):

Many people can work on the same software project at the same time, avoiding problems of code overwriting among the team members.

#2.- Local Backups like a Time Machine:

It allows you to save code as you progress. If in the future you need to travel back in time regarding how the code was, you can do so thanks to Git.

Every time you make a commit, you are basically creating a milestone in time and, above all, saving the version of your software at that moment. Git remembers all changes up to the date you made the commit. This gives you the possibility that if in the future you want to go back to this day when you made the commit, you can do it.

On the other hand, if you use it with Github, it’s excellent because you save or make these commits or backups in Github’s cloud. This gives you the ability to access your project or rather your repository using any browser in the world, share it, or clone it to use it within seconds on any computer.

Some of the most popular or basic commands are the following:

git init 

//Starts and CREATES my local repository by creating a hidden folder called “.git” which contains the entire git program that will track your code versions.

git --version

// The double “–” means a full word follows.

git -v 

// Using only one “-” means an abbreviation follows.

git help 

// Means help or you want to know more about available commands.

git commit -m

// Records or saves changes in your repository.

git config --global user.name "Fernando Tamez" 

// Specifies which programmer or user is using git.

git config --global user.email "email@nubetia.com" 

// Specifies which programmer or user is using git.

git config --global -e 

// Lists info of active user who will be making commits.

*If you want to modify, it’s important when it shows the user to press the letter “a” and to save “:q!”

git status 

//Shows the status of what is being tracked. That is, files that are being tracked and those that are not… or those pending to be saved or committed.

git add 

// Used to start tracking files.

git add . 

// Takes ALL files to send them to the stage and marks them green.

git reset archivo.html 

// Removes file from the stage.

git commit -m "First Commit" 

// Puts that text in the commit description.

After doing this, if I run git status and it shows “On branch master, nothing to commit working tree,” it means everything went well and since the last commit or rather since the snapshot was taken, no changes have been made.

*The commit is usually made every time important changes need to be saved.

git log 

// Shows a log list of every time “git commit” was used.

git checkout -- . 

// Rebuilds or recovers ALL files to the last git commit made.

*If I create another new document, I notice with my visual composer it is marked with another color meaning it is not being tracked.

Example: imagine I make a website and when I finish and have it ready, I want to save it in git to keep a version of my site. So I use the command

git add "fileName.html"

If I write the command “git status,” the file index.html will basically appear in green (meaning it is already staged), so the next step is to take a snapshot so it’s saved, and that is done using the command

git commit or rather git commit -m “Commit description”

I can verify that my change was made if I use the command

git log

git branch -m master main

//Changes the branch name from “master” to the new name “main”

git config --global init.defaultBranch main

//Makes the rename GLOBAL, meaning always, and when creating a repository by default it will be called “main”

Leave a Reply

Your email address will not be published. Required fields are marked *