Showing posts with label Learn Git. Show all posts
Showing posts with label Learn Git. Show all posts

Saturday, April 9, 2016

Learn Git_Project_Recipe Book

1.Go into the veggie-favorites remote
$ cd veggie-favorites/
2.Once inside veggie-favorites make a change to chili.txt and/or squash-lasagna.txt in the code editor.
Click Save, add your changes to the Git staging area, and then make a commit.
$ git add chili.txt                            
$ git add squash-lasagna.txt                   
$ git commit -m "Fisrt commit"                 
[master bd5d061] Fisrt commit                  
 2 files changed, 2 insertions(+)
3.Go into your clone
$ cd veggie-clone/
4.Fetch all new work from the remote.
$ git fetch                                                 
remote: Counting objects: 17, done.                         
remote: Compressing objects: 100% (13/13), done.                                                           
remote: Total 13 (delta 7), reused 0 (delta 0)              
Unpacking objects: 100% (13/13), done.                      
From /home/ccuser/workspace/recipe-book-a/veggie-favorites                                                 
 * [new branch]      master     -> origin/master
5. Merge origin/master into your local master branch .
$ git merge origin/master master                            
Updating 4681ee4..bd5d061                                   
Fast-forward                                                
 chili.txt          | 15 ++++++++-------                    
 margherita.txt     | 11 +++++++----                        
 squash-lasagna.txt |  4 +++-                               
 3 files changed, 18 insertions(+), 12 deletions(-)
6. Create a new branch, then switch over to it to work on new-recipe.txt. The recipe can be whatever dish you'd like.
$ git branch new-branch                                     
$ git checkout new-branch                                   
Switched to branch 'new-branch' 
7.Add your file changes to the staging area and make a commit.
$ git add new-recipe.txt                                    
$ git commit -m "newbranch commit"                          
[new-branch 56a4505] newbranch commit                       
 1 file changed, 1 insertion(+)       
8.Fetch one more time just for good measure (there won’t be a change).
$ git fetch 
9.Push your branch up to the remote.
$ git push origin new-branch                                
Counting objects: 5, done.                                  
Delta compression using up to 3 threads.                    
Compressing objects: 100% (2/2), done.                      
Writing objects: 100% (3/3), 259 bytes | 0 bytes/s, done.   
Total 3 (delta 1), reused 0 (delta 0)                       
To /home/ccuser/workspace/recipe-book-a/veggie-favorites    
 * [new branch]      new-branch -> new-branch
10.Navigate back to the remote,Confirm the presence of your new Git branch there.


                            








Learn Git_Project_JavaScript Homework

1.There is a remote called maryrose-hw which contains your student's JavaScript homework.
Clone the remote, giving it a name of your choice.
$ git clone maryrose-hw/ becky-hw              
Cloning into 'becky-hw'...                     
done
2. Use the terminal command cd to go into your cloned repository.
cd my_clone
Don’t forget to replace my_clone with the name you gave your clone in the previous step.
$ cd becky-hw/ 
3.Use the file navigator to open homework.js in the code editor.
Be sure to open homework.js in your clone, not in the remote.
4.From the terminal, create a new branch with Git. Your branch will be commenting on Mary Rose’s JavaScript homework, so name the branch appropriately.
Next, switch over to your new branch.
$ git branch my-comment                        
$ git checkout my-comment                      
Switched to branch 'my-comment'
5.Time to start commenting on Mary Rose’s JavaScript homework.
6.Add your changes to the Git staging area.
$ git add homework.js        

7.Now, make a commit.              
$ git commit -m "BeckyComment"                 
[my-comment 01ca9d5] BeckyComment              
 1 file changed, 1 insertion(+)  8.Push your branch up to the remote.
$ git push origin my-comment                   
Counting objects: 5, done.                     
Delta compression using up to 3 threads.       
Compressing objects: 100% (2/2), done.         
Writing objects: 100% (3/3), 287 bytes | 0 byte
s/s, done.                                     
Total 3 (delta 1), reused 0 (delta 0)          
To /home/ccuser/workspace/js-homework/maryrose-
hw/                                            
 * [new branch]      my-comment -> my-comment 9.Change directories back to the remote. Use your Git knowledge to see the branch you just pushed. 
cd ../maryrose-hw


Learn Git_Lesson_Git Teamwork

1.Overview
Git offers a suite of collaboration tools to make working with others on a project easier.
Imagine that you're a science teacher, developing some quizzes with Sally, another teacher in the school. You are using Git to manage the project.
In order to collaborate, you and Sally need:
  • A complete replica of the project on your own computers
  • A way to keep track of and review each other's work
  • Access to a definitive project version
You can accomplish all of this by using remotes. A remote is a shared Git repository that allows multiple collaborators to work on the same Git project from different locations. Collaborators work on the project independently, and merge changes together when they are ready to do so. 2.git clone
Sally has created the remote repository, science-quizzes in the directory curriculum, which teachers on the school's shared network have access to. In order to get your own replica of science-quizzes, you'll need to clone it with:
git clone remote_location clone_name
In this command:
  • remote_location tells Git where to go to find the remote. This could be a web address, or a filepath, such as:
/Users/teachers/Documents/some-remote
  • clone_name is the name you give to the directory in which Git will clone the repository.
 The Git remote Sally started is called:
science-quizzes
Enter the command to clone this remote. Name your clone:
my-quizzes
Notice the output:

cloning into 'my-quizzes'...
Git informs us that it's copying everything from science-quizzes into the my-quizzes directory.
my-quizzes is your local copy of the science-quizzes Git project. If you commit changes to the project here, Sally will not know about them.
$ git clone science-quizzes/ my-quizzes                                                          
Cloning into 'my-quizzes'...                                                                     
done.3.git remote -v
We have a clone of Sally's remote on our computer. One thing that Git does behind the scenes when you clone science-quizzes is give the remote address the name origin, so that you can refer to it more conveniently. In this case, Sally's remote is origin.
You can see a list of a Git project's remotes with the command:
git remote -v
3.1.Using the file navigator, examine the contents of the cloned Git project. There are a few quiz files here, which we will be working with during this lesson.
Open a file of your choice in the code editor.

3.2.Change directories into the my-quizzes directory, enter this command on the terminal:
cd my-quizzes
3.3.list the remotes. 
$ git remote -v                                
origin  /home/ccuser/workspace/curriculum/science-quizzes/ (fetch)                            
origin  /home/ccuser/workspace/curriculum/science-quizzes/ (push)  


  • Git lists the name of the remote, origin, as well as its location.
  • Git automatically names this remote origin, because it refers to the remote repository of origin. However, it is possible to safely change its name.
  • The remote is listed twice: once for (fetch) and once for (push).
4.git fetch
After you cloned science-quizzes, you had to run off to teach a class. Now that you're back at your computer, there's a problem: what if, while you were teaching, Sally changed the science-quizzes Git project in some way. If so, your clone will no longer be up-to-date.
An easy way to see if changes have been made to the remote and bring the changes down to your local copy is with:
git fetch
This command will not merge changes from the remote into your local repository. It brings those changes onto what's called a remote branch.
4.1.go into the my-quizzes directory.
$ cd my-quizzes  
4.2.Fetch any new changes Sally may have made to the remote.  
$ git fetch                                                                                      
remote: Counting objects: 6, done.                                                               
remote: Compressing objects: 100% (5/5), done.                                                   
remote: Total 5 (delta 1), reused 0 (delta 0)                                                    
Unpacking objects: 100% (5/5), done.                                                             
From /home/ccuser/workspace/curriculum-a/science-quizzes                                         
* [new branch]      master     -> origin/master    
5.git merge
Even though Sally's new commits have been fetched to your local copy of the Git project, those commits are on the origin/master branch. Your local master branch has not been updated yet, so you can't view or make changes to any of the work she has added.
In Lesson III, Git Branching we learned how to merge braches. Now we'll use the git merge command to integrate origin/master into your local master branch. The command:
git merge origin/master
will accomplish this for us.
5.1.go into the my-quizzes directory

cd my-quizzes


You are on your local master branch. In your commit history, the commit message of the HEAD commit is:
Add first question to Physics quiz
From the terminal, merge with origin/master, where Sally's most recent commits are.
Notice the output:

$ git merge origin/master                                                                        
Updating 2fd7d9b..3a29454                                                                        
Fast-forward                                                                                     
 biology.txt | 4 ++++                                                                            
 1 file changed, 4 insertions(+)                                                                 
 create mode 100644 biology.txt 

Print the commit history.
In the output, notice that the HEAD commit has changed. The commit message now reads:

Add heading and comment to biology quiz



$ git log                                                                                     
commit 3a294546f4a55f02bf37233ef8988d8b9dd7ce59                                                  
Author: danasselin <johndoe@example.com>                                                         
Date:   Tue Nov 3 12:33:23 2015 -0500                                                                                                                                                            
    Add heading and comment to biology quiz                                                                                                                                                      
commit 6aa7704a31d05541141fbb529abf946bd2fd416b                                                  
Author: danasselin <johndoe@example.com>                                                         
Date:   Thu Oct 29 17:04:04 2015 -0400                                                                                                                                                           
    Add biology quiz                                                                                                                                                                             
commit 2fd7d9b248e0b4a3b531b9af3bb61916d42ad45f                                                  
Author: danasselin <johndoe@example.com>                                                         
Date:   Thu Oct 29 15:42:55 2015 -0400                                                                                                                                                           
    Add first question to physics quiz                                                                                                                                                           
commit 2c4e484e0f5bda111a164e6580f4a4a603cea48f                                                  
Author: danasselin <johndoe@example.com>                                                         
Date:   Thu Oct 29 15:42:36 2015 -0400                                                                                                                                                           
    Add physics quiz                                                                                                                                                                             
commit 65be0d3f24fb34363bdac6949325f35ad3cdd98a                                                  
Author: danasselin <johndoe@example.com>    
Date:   Thu Oct 29 15:42:21 2015 -0400                                                                                                                                                           
    Add chemistry quiz                                                                                                                                                                           
commit 9bfc082a0e64efe5c0a2e4298e0b4f127d0a9b96Git has performed a "fast-forward" merge, bringing your local master branch up to speed with Sally's most recent commit on the remote.
6.git workflow
Now that you've merged origin/master into your local master branch, you're ready to contribute some work of your own. The workflow for Git collaborations typically follows this order:
  1. Fetch and merge changes from the remote
  2. Create a branch to work on a new project feature
  3. Develop the feature on your branch and commit your work
  4. Fetch and merge from the remote again (in case new commits were made while you were working)
  5. Push your branch up to the remote for review
Steps 1 and 4 are a safeguard against merge conflicts, which occur when two branches contain file changes that cannot be merged with the git merge command. Step 5 involves git push.
6.1.change directories into the my-quizzes directory. 
6.2.Create a branch to develop questions for the biology quiz. Name the branch bio-questions.
$ git branch bio-questions 
6.3.Switch to your new branch
$ git checkout bio-questions                   
Switched to branch 'bio-questions'6.4.On your branch, open biology.txt in the code editor.
Add a biology question to the file and some sample answers.
6.5.Add biology.txt to the staging area.
$ git add biology.txt  
6.6.Commit the work to the repository with a commit message.
$ git commit -m "First Commit"                 
[bio-questions fcc7550] First Commit           
 1 file changed, 5 insertions(+)  

7.git push
git push origin your_branch_name
will push your branch up to the remote, origin. From there, Sally can review your branch and merge your work into the master branch, making it part of the definitive project version.
7.1.change directories into the my-quizzes directory. 
$ cd my-quizzes/    

7.2.Push your branch up to the remote.

$ git push origin bio-questions                                                                  
Counting objects: 5, done.                                                                       
Delta compression using up to 3 threads.                                                         
Compressing objects: 100% (3/3), done.                                                           
Writing objects: 100% (3/3), 388 bytes | 0 bytes/s, done.                                        
Total 3 (delta 1), reused 0 (delta 0)                                                            
To /home/ccuser/workspace/curriculum-a/science-quizzes                                           
 * [new branch]      bio-questions -> bio-questions
Git informs us that the branch bio-questions was pushed up to the remote. Sally can now review your new work and can merge it into the remote's master branch. 
8.generalizations
  • A remote is a Git repository that lives outside your Git project folder. Remotes can live on the web, on a shared network or even in a separate folder on your local computer.
  • The Git Collaborative Workflow are steps that enable smooth project development when multiple collaborators are working on the same Git project.
We also learned the following commands
  • git clone: Creates a local copy of a remote.
  • git remote -v: Lists a Git project's remotes.
  • git fetch: Fetches work from the remote into the local copy.
  • git merge origin/master: Merges origin/master into your local branch.
  • git push origin <branch_name>: Pushes a local branch to the origin remote.
Git projects are usually managed on Github, a website that hosts Git projects for millions of users. With Github you can access your projects from anywhere in the world by using the basic workflow.

Friday, April 8, 2016

Learn Git_Project_Ruby Time Calculator

1.You are currently on master.
Merge the edits branch into the master branch.
This will create two merge conflicts: README.md and examples.md.
$ git merge edits                              
Auto-merging examples.md                       
CONFLICT (content): Merge conflict in examples.md                                             
Auto-merging README.md                         
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then 
commit the result. 2.Using the file navigator, open README.md and examples.md. Identify the merge conflicts.
examples.md
<<<<<<< HEAD
Created to be intuitive and easy to use, and provide the most crucial functionalites
=======
The commands were written to be intuitive and easy to navigate.
>>>>>>> edits

README.md
<<<<<<< HEAD
Ruby Time is a command line application written in Ruby that manages time and wage calculation, documentation and tax info.
=======
Ruby Time is a command line application written in Ruby that manages time and wage calculation and documentation and tax.
>>>>>>> edits

3.In README.md, keep the file changes from the edits branch. Delete the file changes from HEAD.
Don't forget to delete all of Git's special markings that indicate a merge conflict.
Ruby Time is a command line application written in Ruby that manages time and wage calculation, documentation and tax info.
4.Add README.md to the staging area.
$ git add README.md
5.Follow the same order of actions as above for examples.md: keep the edits branch file changes and delete the HEAD changes.
The commands were written to be intuitive and easy to navigate.
6.Add examples.md to the staging area and make a commit. Your commit message could be "Resolve merge conflict".
$ git add examples.md                          
$ git commit -m "Resolve merge conflict"       
[master 3880061] Resolve merge conflict   
7.Delete the edits branch.
$ git branch -d edits                          
Deleted branch edits (was 63cdad2).

Learn Git_Project_Birthday Party

1.From the terminal, list the Git branches.
$ git branch                                   
* master                                       
  moma                                         
  whitney    
2.Kay wasn't sure where she wanted to host the party, so you made several Git branches to explore different locations.
Some of the branches are no longer needed. Delete the following branches:
moma whitney
You'll need the -D option, because these feature branches were never merged into master:
git branch -D branchname
$ git branch -d moma                           
error: The branch 'moma' is not fully merged.  
If you are sure you want to delete it, run 'git
 branch -D moma'.                              
$ git branch -D moma                           
Deleted branch moma (was 978e5a1). 
$ git branch -D whitney                        
Deleted branch whitney (was 9b384f9).3.Kay wants to see a version of the webpage that includes an unordered list with bullet points instead of a paragraph to show information about the party.
Create a new branch called unordered-list and switch over to it.
$ git branch unordered-list                    
$ git checkout unordered-list                  
Switched to branch 'unordered-list'4.In index.html, replace part of the content.
5.Add index.html to the staging area.
$ git add index.html 
6.Now make a commit.
$ git commit -m "commit on unordered-list"     
[unordered-list 5eddaeb] commit on unordered-list                                             
 1 file changed, 7 insertions(+), 1 deletion(-)
7.Kay approves the changes you made in the unordered-list branch.
Switch over to master. Then, merge unordered-list into master. This will be a fast forward merge.

$ git checkout master                          
Switched to branch 'master' 
$ git merge unordered-list                     
Updating 1481f5a..5eddaeb                      
Fast-forward                                   
 index.html | 8 +++++++-                       
 1 file changed, 7 insertions(+), 1 deletion(-)
8.Kay wants the heading to be way bigger. Create a new branch called big-heading.
$ git branch big-heading
9.Now, switch over the the big-heading branch.To make the heading bigger, replace the line with something else.
$ git checkout big-heading                     
Switched to branch 'big-heading'10.Add index.html to the staging area.
$ git add index.html 
11.Make a commit. 
$ git commit -m "Big heading"                  
[big-heading bbf14a7] Big heading              
 1 file changed, 1 insertion(+), 1 deletion(-)
12.Kay approves of the giant heading! Switch back over to the master branch. Then, merge big-heading into master.
$ git checkout master                          
Switched to branch 'master'                    
$ git merge big-heading                        
Updating 5eddaeb..bbf14a7                      
Fast-forward                                   
 index.html | 2 +-                             
 1 file changed, 1 insertion(+), 1 deletion(-)




Learn Git_Lesson_Git Branching

1.git branch
Up to this point, you've worked in a single Git branch called master. Git allows us to create branches to experiment with versions of a project. Imagine you want to create version of a story with a happy ending. You can create a new branch and make the happy ending changes to that branch only. It will have no effect on the master branch until you're ready to merge the happy ending to the master branch.
You can use the command below to answer the question: “which branch am I on?”
$ git branch
1.1.Check what branch you are currently on.
In the output, the * (asterisk) is showing you what branch you’re on.
$ git branch                                                                                     
master
2.branching overview


The diagram below illustrates branching.

  • The circles are commits, and together form the Git project's commit history.
  • New Branch is a different version of the Git project. It contains commits from Master but also has commits that Master does not have.
3.git branch 2
 Right now, the Git project has only one branch: master.
To create a new branch, use:
$ git branch new_branch
Here new_branch would be the name of the new branch you create, like photos or blurb. Be sure to name your branch something that describes the purpose of the branch. Also, branch names can’t contain whitespaces: new-branch and new_branch are valid branch names, but new branch is not.
3.1.Create a new branch called fencing.Next, view your branches as you did in the previous exercise. Notice in the output there now appear two branches: master and fencing
$ git branch fencing                                                                             
$ git branch                                                                                     
  fencing                                                                                        
* master 4.git checkout
The master and fencing branches are identical: they share the same exact commit history. You can switch to the new branch with
git checkout branch_name
You will be now able to make commits on the fencing branch that have no impact on master.
4.1.Switch to the fencing branch from the master branch.
$ git checkout fencing                                                                           
Switched to branch 'fencing' 
4.2.Use git branch to verify that you have switched branches.
In the output, notice the * is now over the fencing branch.
$ git branch                                                                                     
* fencing                                                                                        
  master    
5.commit on a new branch
The diagram below shows what will happen to the Git project. 


5.1.Print the Git commit log.
Notice the output:

  • The commits you see were all made in the master branch. fencing inherited them.
  • This means that every commit master has, fencing also has.
Note: if you find that your cursor is stuck in Git log, press q to escape.
$ git log                                     
commit 79a1cc5e23d46fd2f4459440cc18624d874cf36
Author: danasselin <johndoe@example.com>      
Date:   Wed Oct 28 17:10:17 2015 -0400                                                     
    Add heading for volunteer experience                                                   
commit df765b18c9b767089ef649f7ece33b58c27b897
Author: danasselin <johndoe@example.com>      
Date:   Wed Oct 28 17:09:50 2015 -0400                                                     
    Add experience scheming against hook                                                   
commit 1baf497026042a0938bc353c2d5406e31860f43
Author: danasselin <johndoe@example.com> 
5.2.In resume.txt,
Delete this line:

-Scheme against Captain Hook
and type this line in its place:

-Engage in swordfights with pirates
5.3.Add resume.txt into the staging area. $ git add resume.txt                           5.4commit on a new branch
Commit the changes to the repository with a commit message. 
$ git commit -m "Commit to Fencing fetch"     
[fencing 2c38d27] Commit to Fencing fetch     
 1 file changed, 1 insertion(+), 1 deletion(-)
6.git merge
What if you wanted include all the changes made to the fencing branch on the master branch? We can easily accomplish this by merging the branch into master with:
git merge branch_name
In a moment, you'll merge branches. Keep in mind:
  • Your goal is to update master with changes you made to fencing.
  • fencing is the giver branch, since it provides the changes.
  • master is the receiver branch, since it accepts those changes. 
6.1.You are currently on the fencing branch. Switch over to the master branch.
$ git checkout master                                                                            
Switched to branch 'master'
6.2.From the terminal, merge the fencing branch into the master branch.
Notice the output: The merge is a "fast forward" because Git recognizes that fencing contains the most recent commit. Git fast forwards master to be up to date with fencing.

$ git merge fencing                                                                              
Updating 79a1cc5..2c38d27                                                                        
Fast-forward                                                                                     
 resume.txt | 2 +-                                                                               
 1 file changed, 1 insertion(+), 1 deletion(-)                                                  
7.merge conflict I
The merge was successful because master had not changed since we made a commit on fencing. Git knew to simply update master with changes on fencing.
What would happen if you made a commit on master before you merged the two branches? Furthermore, what if the commit you made on master altered the same exact text you worked on in fencing? When you switch back to master and ask Git to merge the two branches, Git doesn't know which changes you want to keep. This is called a merge conflict.

7.1.You are on the master branch. In the code editor, where you have written:

-Engage in swordfights with pirates
Add the word "professional", so the text reads:

-Engage in swordfights with professional pirate
7.2Add resume.txt to the staging area. 
$ git add resume.txt  
7.3.Commit the changes to the repository with a commit message.
$ git commit -m "change to professional"       
[master 8f4ab6c] change to professional        
 1 file changed, 1 insertion(+), 1 deletion(-)
7.4.Imagine a few weeks have passed, and you'd like to develop your fencing resumé some more.
Switch back to the fencing branch.
$ git checkout fencing                         
Switched to branch 'fencing'
7.5.From fencing, change the line so it reads:

-Engage in swordfights with professional pirates such as Smee.

7.6.Once again, add resume.txt to the staging area. 
$ git add resume.txt 
7.7.Commit the changes to the repository with a commit message.
$ git commit -m "Smee"                        
[fencing 700e536] Smee                        
 1 file changed, 1 insertion(+), 1 deletion(-)
8.merge conflict II
Let's say you decide you'd like to merge the changes from fencing into master.
Here's where the trouble begins!
You've made commits on separate branches that alter the same line in conflicting ways. Now, when you try to merge fencing into master, Git will not know which version of the file to keep.
8.1.Switch to the master branch. 
$ git checkout master                          
Switched to branch 'master' 
8.2.merge fencing into master.In the output, notice the lines:
$ git merge fencing                            
Auto-merging resume.txt                        
CONFLICT (content): Merge conflict in resume.txt                                              
Automatic merge failed; fix conflicts and then 
commit the result. 
8.3.We must fix the merge conflict.
In the code editor, look at resume.txt. Git uses markings to indicate the HEAD (master) version of the file and the fencing version of the file, like this:

<<<<<<< HEAD master version of line ======= fencing version of line >>>>>>> fencing
Git asks us which version of the file to keep: the version on master or the version on fencing. You decide you want the fencing version.
From the code editor:
Delete the content of the line as it appears in the master branch
Delete all of Git's special markings including the words HEAD and fencing. If any of Git's markings remain, for example, >>>>>>> and =======, the conflict remains.
Try reloading the page if Git's markings don't show up.
 -Engage in swordfights with professional pirates such as Smee.
8.4.Add resume.txt to the staging area. 
$ git add resume.txt 
8.5.Now, make a commit. For your commit message, type "Resolve merge conflict" to indicate the purpose of the commit. 
$ git commit -m "Resolve mrege confict"        
[master 2c0a4f9] Resolve mrege confict  9.delete granch
In Git, branches are usually a means to an end. You create them to work on a new project feature, but the end goal is to merge that feature into the master branch. After the branch has been integrated into master, it has served its purpose and can be deleted.
The command
git branch -d branch_name
will delete the specified branch from your Git project.
Now that master contains all the file changes that were in fencing, let's delete fencing.

9.1.Delete the fencing branch.
Now, verify that you have indeed deleted fencing by listing all your project's branches on the terminal.
Notice in the output that only one branch, master, is shown.
$ git branch -d fencing                                                                          
Deleted branch fencing (was 700e536).                                                            
$ git branch                                                                                     
* master 
10.generalizations
Git branching allows users to experiment with different versions of a project by checking out separate branches to work on.
The following commands are useful in the Git branch workflow.
  • git branch: Lists all a Git project's branches.
  • git branch branch_name: Creates a new branch.
  • git checkout branch_name: Used to switch from one branch to another.
  • git merge branch_name: Used to join file changes from one branch to another.
  • git branch -d branch_name: Deletes the branch specified.