DEV Community

Cover image for Squeezed GIT
Kimia Kamrava
Kimia Kamrava

Posted on

Squeezed GIT

In Turkish, the word "git" means go!! it felt more like run!!!
GitHub was a little bit confusing for me but after some time it makes more sense, first let's talk about four fundamental elements in the GIT so we can understand what's going on. we have this office or folder which is our ##local directory.

Alt Text

Then we have index , also called stage

Alt Text
also the local repository

Alt Text

and finally the remote repository.

Alt Text

If we consider a file in our workspace it can be in three possible states:
1.it can be committed
2.modified which is the case of the file being changed and none of these changes being saved to the local repo.
3.it can be staged which means that the file is basically part of this index that means it's been tagged to be considered in the next commit.

Now let's talk about why and when we use the commands.

The first command that we usually run in case we are getting access to a remote repository is

git clone

oops did I go too fast?
let's do it together and set up GitHub :

git config --global user.name"[firstname lastname]"

set a name that is identifiable

git config --global user.email "[valid-email]"

set an email address that will be associated with each history marker

git config --global color.ui auto

set automatic command line coloring for Git for easy reviewing.

SETUP & INIT

git init

initialize an existing directory as a Git repo

git clone

Alt Text

yaay so we just started with this step together. the git clone followed by the URL for that repository will create a local copy of the repository in our workspace and yes if we are creating the repository.
the next command is the command add, and what the command add does is to add a file that is in the workspace to index.
Now our file is staged and it's marked to be committed but not yet.
So what we need to do is to commit the file.

git commit

now all the files that are staged, their changes will be committed to the local repository.
At this point, our changes are safely stored in the Local repository.we can also perform these two steps at once by executing a Commit -a.

Alt Text

after discussing centralized and decentralized, there is a local repository, now we have to push our changes to a remote repository and this is were

git push

command does.it pushes the changes in the local repository to the remote repository.
what if we wanted to get our data files from the local repository to our workspace.well yaaaay we have a command for that too

git merge

in case we wanted to get the changes directly to our workspace with single command..magic:

git pull

as we can see git pull and git merge they have the same effect why we use git merge if we can do everything in one command?
because it allows us to compare files before we actually get the latest version of the file.
Basically, GitHub is a room filled with folders and we are trapped inside of all these files and folders. And there are ways to send the files to other rooms, Change it and get it back ad, etc ...
These were the basic commands. There are many cheat sheets out there that we can use.

I hope this was helpful just a little bit:)

Top comments (0)