RubyLit - Ruby.del.litoral!
Tutorial de Git (Rev #6)

Tutorial git
Original source: http://hoth.entp.com/output/git_for_designers.html

Version control, also known as source control or revision control is an integral part of any development workflow. Why? It is essentially a communication tool, such as emails or IM, but it works with code instead of human speech.
Version Control
  • Allows programmers to easily communicate their work to other
  • Allows a team to share code
  • Maintain separate versions of “production” are always deployables
  • Allows the simultaneous development of different characteristics in the same code base
  • Keeps track of all the older versions of files like “Point of Sale Software” http://www.merchantos.com/
  • Prevents overwriting work
  • What is version control?

 Version control, alternately known as source control or source code management is a system that maintains versions of files in the progressive stages of development. The version control system is similar in theory to back up your files, but smarter. Each file in the system has a complete history of changes, and can be easily restored to any version of history. Each version has a unique identifier that looks like a string of letters and numbers. (443e63e6..).

There are many different software version control. This document is based on git, but also can study Subversion (SVN), CVS, darcs, Mercurial and others. Each has a Slightly Different metaphor for operation.

  • Repository Structure
    The simplest version of the version control system consists of a repository where all the files and their live versions. Just a repository works as a database, you can return any version of any file in, or change history of any file, or perhaps a history of changes through the entire project.
    1. 25 Joe Adjust user profile information
    2. 24 Fred Add login box
    3. 23 Mary Allow user uploads photo
    4. 22 Joe Change the color of the header to yellow
    5. 21 Mary Change the header to blue
      The user repository can check out a working copy, which is paying attention in recent copies of files that users can apply changes. After making some changes, users can then type in (check in or commit) the changes to the repository, which creates a new version with metadata regarding changes that were implemented and the person who made them.

http://hoth.entp.com/output/scm.png

Figure 1: A basic version control

While the simplest way is to have a canonical source for the repository, this is not necessary. Each user has a complete copy of the repository on your local machine. Generally, you apply changes to your local repository, and once it is complete, press down (push) your work to the shared repository on your computer. You can also pull (pull) of changes in other repositories

http://hoth.entp.com/output/dscm.png

Figure 2: A system of distributed source control

  • Branches (Branches)
    The branches serve the same role that the draft when you write an email. You can work on a draft, saving it frequently until it is complete., Then, when ready, send email, and the draft is eliminated. In this case, the Sent folder does not pollute with your changes frequently, until you press “send.”
    The branching is useful when developing new features, because it allows the teacher-branch Sent folder – be always working and deployable. It can be any number of experimental-draft-branches in active development. The branches are easy to create and exchange.
    Once the code is finished in a branch and the branch passes its tests, the changes are mixed (merged) into the master branch and the branch is removed, as with mail draft. If someone applies for code changes (commit) to the master branch, it is easy update the master code to the last branch.
  • Workflow (Workflow)
  • Attack of the Clones
    To have a working copy of your code base, you need to clone a remote repository on your local machine. The cloned creates the repository and gets the latest version, which is referred to as HEAD.
    We cloned an open-source project.
    $ Git clone git: / / github.com / wycats / jspec.git
    Initialized empty Git repository
    Congratulations, you’ve cloned your first repository. Command Sets clone and convienientes few items for you, keeps the original repository address, nickname given him in origin, so that you can easily send the changes back (if you have permission) to the remote repository.
    JSpec now have a folder in the current directory. If you cd into that directory, you should see the contents of JSpec source code (they are only a few files)
    Git can run on many protocols, including “git: / /” as above (most public projects use git ://). By default, git uses the ssh protocol, which requires you to have secure access to the remote repository.
    $ Git clone user@yourserver.com: thing.git
    You can specify the details of your authorization to ssh as above,
  • Making changes
Now that you have a working copy, you can start making changes. There is nothing magical about editing files, so all you need do is edit the files you whatever and then save them. Once the file is saved, you need to add (add) a change to the current revision (or more typically, you will make changes to several files and add them to the current review all at once). To do this, you need to git add to add the file with changes. This is known as “staging.”
$ Git add index.html
Or you can also add an entire directory at once,
$ Git add public /
That will add any file in the public / a review, or add the current directory:
git add.
If you make any changes after staging (before commit), you need to git add the file again.
Git status command displays the current status of the repository.
ninja-owl: public Courtenay $ git status
  1. On branch master
  2. Changes to be Committed:
  3. (Use “git reset HEAD <file> ...” to unstage) #
  4. Modified: public / index.html #
    Git diff command shows you a view that difference is what has changed. By default, shows the changes that have not been “Estager.” Adding the flag ” cached” show changes “Estager” only.
    ninja-owl: public Courtenay $ git diff – cached
    diff – git a / public / index.html. b / public / index.html
    100 644 index 754492nd a04759f ..
    A / public / index.html
    + B / public / index.html
    -8.7 +8.6 Source code revision control or management, is a system That Maintains versions

This That I added a line to the file
This is a line I removed from the file
This output is called a diff or match and may be sent by email to other developers so that they can apply your changes to your local codes. It is also human-readable: shows the file names, line numbers within the file, and changes with the symbols
and . You can also tubing (pipe) the diff to a file.
ninja-owl: public Courtenay $ git diff – cached> line_modify.patch
Commit (commit) something in your life
When you have your changes so you want to add them to the current revision, then you need to commit (commit) this review to your local repository. To do this, you will need to run git commit. When you execute this command, you receive a text editor with a list of files that have changed and some empty space at the top. In this space, you need to describe what has changed so that your colleagues can tell at a glance what you have done. Need to enter something better than “thing”, but there is no need to write a will, and instead do something like:
434 in line Changed index.html to use Rather Than spaces tabs.
Changed line 800 in products.html.erb to Have Space Between the two tags.
Changed line 343, 133, 203, 59, and 121 to Have two spaces at the start Rather Than 9.
Corrta A description of what you have changed will be sufficient. The commit messages are an art form, like haiku.
Minor formatting changes file in the code.
It is acceptable to write a summary line (less than 80 characters), a blank line, then a third line describing in more detail. The second and third lines are optional.
Once you’ve written the commit message, save the file and quit the text editor. This will commit to your local repository, and you can continue with your work.
Push back
Once your changes have been “committed” to your local repository, you need to push (push) the remote. To do this, you will need to run git push, which will push all changes from your local repository to the remote.
The push to git takes several arguments:

git push <repository> <branch>
</ Pre>

In this case, we want to push changes back to the original repository, which is "nicknamed" as origin, to the branch master.

<pre>
$ Git push origin master
</ Pre>

Fortunately for our fingers, push git (and git pull) default push and pull of all the branches common to the origin and local repository.
As you do push, you should see output similar to the following:

<pre>
your-computer: git_project yourusername $ git push

updating 'refs / heads / master'
  from fdbdfe28397738d0d42eaca59c6866a87a0336e2
  to 1c9ec11f757c099680336875b825f817a992333e
 Also local refs / remotes / origin / master
Generating pack ...
Done counting two objects.
Deltifying two objects ...
 100% (2 / 2) done
Writing two objects ...
 100% (2 / 2) done
Total 2 (delta 3), reused 0 (delta 0)
refs / heads / master: fdbdfe28397738d0d42eaca59c6866a87a0336e2 -> 1c9ec11f757c099680336875b825f817a992333e
</ Pre>

All this output basically says that you have your files ready to be pushed (pushed) (Generating pack) and the remote repository has received your files (Writing two objects). Then the remote repository has updated its head / master (the branch "main" repository) to the revision tipped you have committed (commit) by what is known as the last set of changes committed. Now others can update their local copies to be synchronized with the changes you've done. But how are you doing this?
Get updates from afar
To update your local repository and a working copy to the last revision committed to the remote repository, you need to run git pull. This "pulls" all changes from the remote repository and combines them with your current changes (if any).
When you run a git pull, the output should look something like this:

<pre>
remote: Generating pack ...
remote: Done counting 12 objects.
remote: Result has eight objects.
remote: Deltifying 8 objects ...
remote: 100% (8 / 8) done
Unpacking 8 objects ...
remote: Total 8 (delta 4), reused 0 (delta 0)
 100% (8 / 8) done
* Refs / remotes / origin / master: fast forward to branch 'master' of git@yourco.com: git_project
  old .. new: 0c793fd fdbdfe2 ..
Auto-merged file.cpp
Merge made by recursive.
 . Gitignore | 2 + +
 file.cpp | 8 ++++++--
 src / things.html | 5 +++--
 your_file.txt | 18 ++++++++++++++++++
 4 files changed, 19 insertions (+), 4 deletions (-)
 100 644 create mode. gitignore
 100 644 create mode your_file.txt
</ Pre>

What has happened is basically a push in reverse. The remote repository has been prepared and transferred to your local repository changes (Unpacking 8 objects). Your local repository and then making the changes implemented in the same order they were committed (eg combined as the example for file.cpp or creating them as. Gitignore your tu_archivo.txt
Note: The. Gitignore allows you to tell Git to ignore certain files and directories. This option is useful pathings like binary ra generated log files, or also those with local passwords on them.
Branching
You should always create a branch before starting work on a new feature. Thus, the master will always be in a stable state, and you'll have the opportunity to work in isolation from other changes. Creating new branches allows you to take the branch master, "clone", and apply changes to this "cloned." So when you're ready, you can mix your branch with the master, or, if there have been changes to the master while you were working, mix your own branch. It's like pulling and pushing, but everything happens in the same directory. The figure below illustrates the process.
http://hoth.entp.com/output/branching.png

Figure 3: Branching and mixing (merging)

The branching is great for two people to work together on things that require isolation of the main codebase. This could include anything from code that will have permanent results, such as a really big code refactoring or redesign a site, to temporal things, such as performance testing.
Creating a branch (Branch)
To create a Branch in Git, you execute you git checkout - b name> rama>. Any modified file will be listed.

<pre>
$ Git checkout-b redesign
M public / index.html
Switched to a new branch "redesign" 
</ Pre>

Now you've checked the branch redesign. To switch to the master,

<pre>
$ Git checkout master
M public / index.html
Switched to a new branch "master" 
</ Pre>

You'll find very useful to establish the branch in the remote repository, so that others can pull your changes.

<pre>
$ Git push origin redesign
</ Pre>

You can also push your branch to another branch remotely different

<pre>
$ Git push origin redesign: master
</ Pre>

This sets the current working copy to commit and push all changes to branch redesign in local and remote repositories. Now any changes you add and comets live in this branch instead of the master.
Aside: In what branch I am? To view your current branch, and to list all local branches git branch runs
If you need to pull changes from your master branch (ie, major changes in code, security updates, etc) you can do using

<pre>
git pull:
git pull origin
git merge master
</ Pre>

This command tells Git to pull all changes from the repository origin (the name for the repository canonical Git remote) including all branches. Then combine the master branch to yours. When you're ready to combine with the master, you need to check to master, and then combine the branches:

<pre>
git checkout master
git merge redesign
</ Pre>

Now your changes will be combined to the master branch from the branch redesign. If finished with the branch you created, you can delete it using the-d.
git branch-d redesign
To delete the branch in the remote repository, you must capture the push command (remember that you can push a local branch to a remote branch with git push <remote> <local branch>: <remote branch>) and send a local branch empties remote branch.

git push origin: redesign
More useful tools
Undoing your changes
You can remove a file from the staging with git reset HEAD <filename>.
If you want to revert a file to copy in the repository, only Check it again. git checkout <filename>
To revert a file to an older version, use git checkout. Need to know the ID of review, where you can find with git log

<pre>
$ Git log index.html
86429cd28708e22b643593b7081229017b7f0f8d commit
Author: joe <joe@example.com>
Date: Sun February 17 2008 22:19:21 -0800

    build new html files

3607253d20c7a295965f798109f9d4af0fbeedd8 commit
Author: fred <fred@example.com>
Date: Sun February 17 2008 21:32:00 -0500

</ Pre>

    Oops.
To revert the file to the older version (360 725 ...) run checkout. Git draw up the previous version for you, ready for review and commit.
$ Git checkout 3607253d20c7a295965f798109f9d4af0fbeedd8 index.html
If you do not want to restore this old version, you can go back again.

<pre>
$ Git reset HEAD index.html
$ Git checkout index.html
Or in a command
$ Git checkout HEAD index.html
</ Pre>

Have you noticed that is interchangeable with the HEAD revision number? This is so because git, revisions and branches are effectively the same thing.
Who wrote that line?
Run git blame <file> to see who last changed the file and when.
View the full tree
You can view a detailed history of your working copy with gitk.
http://hoth.entp.com/output/gitk.png

Figure 4: Sample gitk screenshot
 Gitk application allows you to navigate through the tree of changes, see diffs, find old reviews and more.
Best practices
We think we can pass this section with a few hints and tips that can help when working with version control systems.
Commits (commit) often
Like when people always say "records often or you'll regret" when trabajs with word processors, you should commit to your local repository as often as possible. Not only protects you from the possibility of losing your job (should not happen if you follow the prime piece of this notice), but will give you security that you can go back anytime you need it. Of course, of course, commit Committing Every after-commit or commit wocommitrd lcommitecommittcommittcommitecommitrcommit could be a bit excessive. At each step you make to your work, you should commit. you take in your work, you should commit.
Throw often
Conversely, you should throw often. Shooting often keeps your code up to date and, hopefully, eliminate the possibility of duplicating work. It is always frustrating when you spend hours working on a property and your colleague and implemented and pushed to the repository, but did not know because it strips every three weeks.
Use checkout and carefully reset
To reverse any local changes you've made to a specific file from your last commit, you can use git checkout <filename>, or also use git reset to kill all changes since your last commit. Having the ability to back steps back is a great tool (especially if you realize that you follow a path completely wrong), but it's definitely a double-edged sword. Once the changes were, they were, so beware!. It's terrible when you realize you threw overboard a few hours of work for a reset of no return.
Create your own repository anywhere.
If you have some control simpre versions in a local project (eg, has a great remote repository or similar), then you can simply use git init to create your own local repository. For example, if you're working on some design concepts of an application, then you could do something like this:
mkdir design_concepts
git init
Now you can add files, commit, branch, and so, as in a remote Git repository "real." If you want to push and pull, you need to configure a remote repository.

I advise you to write setings in the "essay" http://custom-essay-writing-service.org/index.php and "safety Cover" http://www.cheappoolproducts.com.

<pre>
git remote add <alias> <url>
<alias> master git pull
</ Pre>