divendres, 26 de setembre del 2014

Basic Git workflow





Open the Terminal, and create a directory named test wherever you  want, here we create the test directory on /tmp:


$cd /temp

/tmp $ mkdir test

/tmp $ cd test
/tmp/test$

Now we will create two files:

/tmp/test $ touch one.txt two.txt
/tmp/test $ ls
  one .txt two.txt

Right now we just have  a directory with two files.
Now we want to put our directory under version control. In order to do that we will write:

/tmp/test $ git init

Initialized empty Git repository in /private/tmp/test/.git/

What happened? Well, Git has just created a database of commits and a staging area, both void. Before the command git init we had just a directory, now we have three things: a directory, a staging area, and a database of commits.

Now let's put the two files on the staging area:

/tmp/test $ git add .

The staging area is just a virtual area when snapshots of changes are placed (using git add) before they are commited.
Now we can commit (take a snapshot or photo of the staging area):

/tmp/test $ git commit -m "First commit"

Ok, so now we have a first commit on our version control. We can see a list of commits with git log:

/tmp/test $ git log --oneline
4d6cf82 First commit

We have our commits saved on the local database.  But, what if we want to save on a public repository like GitHub?
That's easy. Go to github.com and create  a public repository: 




Once created, we go back to terminal and type:

/tmp/test $ git remote add origin https://giria@github.com/giria/test.git

That is, "add a remote repository called origin with that url"
Once added the remote repository, we can just push our local files to the servers of GitHub;

/tmp/test $ git push origin master
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 210 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://giria@github.com/giria/test.git
 * [new branch]      master -> master

And now our files, with all story of commits are stored on GitHub.

Cap comentari:

Publica un comentari a l'entrada