What's new

Closed Front-end development series 08 | basics in git

Status
Not open for further replies.

_iamkurt

Honorary Poster
Joined
Aug 13, 2017
Posts
463
Reaction
308
Points
224
In this thread, let us start creating our first Git repo and start working on our first project. But first, make sure to turn off your CentOS 7 VM and login as root.

If na miss nyo previous thread, see below:

Front-end development series
Front-end development series | setup VM for centos 7
Front-end development series | install centos 7 in VM
Front-end development series 04 | connect centos 7 on the internet
Front-end development series 05 | install ssh in centos 7
Front-end development series 06 | install httpd
Front-end development series 07 | install nodejs, yarn, gulp, and git

Sa mga starters, working directory natin ay /var/www/html. The said directory is the default working directory after we have installed httpd in your VM. With that said let us change our working directory by:
Code:
cd /var/www/html
— for starters, to change directory in Linux, the command is cd <directory name>


From here, let us create your own working directory, for example, PHCorner. To do so, run:
Code:
mkdir PHCorner
— to create a directory/folder in Linux, the command is mkdir <directory name>, mkdir stand for make directory.

Then cd to PHCorner, run:
Code:
cd PHCorner

If you wish to check your current directory, try pwd:
Code:
[root@localhost PHCorner]# pwd
/var/www/html/PHCorner
pwd, means print working directory.


If same you have the same output, let us start by initializing Git, by git init:
Code:
[root@localhost PHCorner]# git init
Initialized empty Git repository in /var/www/html/PHCorner/.git/
git init means create an empty Git repository. What do you mean by repository? — a place where things are or may be stored.

Try list all your current files for you to see the .git directory instead. Run ls -a
Code:
[root@localhost PHCorner]# ls -a
.  ..  .git
ls means lists all of the files in the current directory
-a, --all tag means do not ignore entries starting with (.)

Ayun, may .git directory na. Magaling :)

Set mo yung global user email at name mo. Dito mo ma identify kung sino ang ng push ng changes sa repository mo. For example,
Code:
git config --global user.email "ign0.ranc3@yahoo.com"
git config --global user.name "ign0ranc3"

Try mo view changes mo by git config --list, for example,
Code:
[root@localhost PHCorner]# git config --list
user.email=ign0.ranc3@yahoo.com
user.name=ign0ranc3
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

At this point, we tell Git that this will be our working directory from now on — For starters, let us create our first file and understand these git add, git commit, git status and git push command. In our project, let us create our first README file. To do so, run the command below:
Code:
touch README.md
touch <filename>, another way on how you create a file in Linux


Then, let us edit README.md using nano, as our terminal editor. If hindi nyo pa na install si nano run mo lang ang command nato:
Code:
yum nano -y


Okay, let us edit README file by:
Code:
nano README.md
nano <filename>
uyaHgB.png

From here, you place your short description of this project. For example:
bN7iXh.png

Press ctr + x, then press y and enter, to save your changes. Yan ang steps on how to save your changes in nano.

Now, what is git status? — git status shows the state of the working directory and the staging area. git log shows committed snapshots and lets you list, filter or search history.

Dito ang list ng directory and files na hindi mo pa na save sa repository mo. From example, run command git status:
25HR4t.png
Para saan ito magagamit? — madali mong makita anong files ang bago or merun changes. In our case, we have README.md. Bakit README.md? — is used to generate the HTML summary you see at the bottom of projects.

Ngayun, gusto mo e save yung changes mo, run mo nlang ang git add . — For example,
Code:
[root@localhost PHCorner]# git add .
git add (.), means, add all new and edited files on this directory, which explains the (.)

Try mo run git status, nka list yung new file natin, for example.
PxdjUb.png

Simple lang diba? Lagyan natin ng label yung changes natin para alam mo para saan yung files. Run mo git commit -m "message mo". From example,
N904B2.png
What is git commit? — is used to save your changes to the local repository

Ayun, magaling. Marunong ka nang mag add, commit, sa git. Ngayun, if you wish to view all the commits, run git log. For example:

Code:
[root@localhost PHCorner]# git log
commit f791321dc93b80aa79bccbb67c8dec8596e43ba3
Author: ign0ranc3 <ign0.ranc3@yahoo.com>
Date:   Sat Nov 3 01:29:51 2018 -0400

    first commit ko sa PHCorner
[root@localhost PHCorner]#

Paano ma malalaman if na commit mo na lahat ng changes mo sa local repository mo? Try git status again. For example.

Code:
[root@localhost PHCorner]# git status
# On branch master
nothing to commit, working directory clean
[root@localhost PHCorner]#

Yan, mahusay. Sana may natutunan kayo diyan specially for starters. If merun, like mo naman. Next thread, tignan natin kung paano e push yung local repository natin sa remote (Github)

I will keep you updated.
 

Attachments

Last edited by a moderator:
Status
Not open for further replies.

Similar threads

Back
Top