Saturday, October 31, 2015

How to use git and github on Lubuntu


On previous article i show you how to install git on lubuntu, now i'm going to show you how to use git and github on lubuntu.

Github is an online service where you can store online repository of git, so you can create local repository and push it online or create online repo and then clone it locally.

Okay first, i want you to create an account on github.com, don't worry it's totally free as long as you choose the free plan option when you create account on github.





And then i want you to create repository on github, just named it 'my_first_repo' or something like that, up to you, but for this tutorial i use 'my_first_repo' as the name of the repo.

Next on your lubuntu, open up the terminal/console, and clone the repo that you have just created on github to your local computer.

For example the clone url of my repo is : 

https://github.com/lubuntuhowto/my_first_repo.git

So to clone that repo on my computer, i run this command:

git clone https://github.com/lubuntuhowto/my_first_repo.git

The repo 'my_first_repo' will be copied to your local computer, there will be a directory named after the repo that you have just clone.

git clone https://github.com/lubuntuhowto/my_first_repo.git
Cloning into 'my_first_repo'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.

So now, you can navigate to that directory to start working on that repo, simply type this command to move to 'my_first_repo' directory:

cd my_first_repo

Once you are inside that directory, you can start using git commands, such as git status, this command is to check the status of your current working branch.

git status
git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

Next let's create our first commit, to do that you must make some change on the repo, create files or editing any existing files so that you can make a commit and then push your work to github.

touch sample.php

Now run git status again, to see if there's any changes

git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add ..." to include in what will be committed)

	sample.php

nothing added to commit but untracked files present (use "git add" to track)

Yup, git detected new file (untracked files) on the branch 'master' and asking you to add the file to stage, so that later you can make a new commit, if that makes sense.

So to add files to put on stage, simply use git add . command, like this:

git add .

Now run git status again, to see what's happening on your branch

git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD ..." to unstage)

	new file:   sample.php

As you can see there is a new file called sample.php and you need to create a commit, to create a commit simply use git commit -am "the description of the commit".

git commit -am "create new file called sample.php"

At this point, you already made some changes to the branch and already make a commit, next you can store the commit to github, by using git push command:

git push origin master
git push origin master
Username for 'https://github.com': lubuntuhowto
Password for 'https://lubuntuhowto@github.com': 
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 290 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/lubuntuhowto/my_first_repo.git
   949fd63..89e260c  master -> master
Now i want you to go to github see if there's any changes, well you should see changes on github, because you have just successfully push to github with no error.

If you following this short tutorial correctly, you should now have better understanding about git and github and how they related to each other. 

No comments:

Post a Comment