Git: Working with Remotes from the Command Line

From Foss2Serve
(Difference between revisions)
Jump to: navigation, search
 
(22 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
{| border="1"
+
 
|-
+
{{Learning Activity Overview
|'''Title''' ||Cloning a Module Using Git
+
|title=
|-   
+
Setting up Git Server
|'''Overview''' ||
+
|overview=
Open source community comes with many different applications and modules which are constantly under development. In order to become familiar with a particular module, you need to clone the module on your virtual machine. Almost all the open source modules developed by the community use version control systems to manage and organize the changes. This document provides steps to clone a module from one such version control system.
+
Git is an open source distributed version control system originally developed to support the development of the Linux kernel.  
 +
 
 +
Using  git clone [url]  , you can clone a repository. 
 +
 
 +
Every Git working directory is a full-fledged repository with complete history and full version tracking capabilities, not dependent on network access or a central server.
 +
|prerequisites=
 +
Version Control/Repository
 +
|objectives=
 +
* Set up Git
 +
|process skills=
 +
}}
 +
 
 +
=== Background ===
  
 
Version Control:
 
Version Control:
Line 15: Line 27:
 
Git can be used as a local version control system without having any central repository.
 
Git can be used as a local version control system without having any central repository.
  
 +
Some of the basic Git commands are listed here.
  
 +
Clone: Downloads the project and its entire history.
  
|-
+
$ git clone [url]
|'''Prerequisite Knowledge''' ||Familiarity with Git Server
+
  
 +
Branch: Lists/creates new branch
  
|-
+
$ git branch [branch-name]
|'''Learning Objectives''' ||Cloning using Git;   
+
|}
+
  
=== Background: ===
+
Checkout: Switches between branches / updates working directory.
The installed version of Fedora Operating system has git version control system preinstalled. If not, please refer to the document Lab - Setting up git.docx and install it before proceeding further.
+
To check if git was installed and working correctly, open VirtualBox and start Fedora 22 Operating System.
+
After logging in to the Virtual Machine using the user credentials created during installation, open terminal program as shown below.
+
  
1. Click on “Activities” on the top left and type “Terminal” in the search bar.
+
$ git checkout [branch-name]
  
2. Now click on the Terminal Button displayed in the search results and type the command “git” in the command line.
+
Pull: Fetches all the history and merge to working directory.
Please refer to https://git-scm.com/docs for getting familiar with all the git commands available.
+
=== Directions: ===
+
'''Cloning a module using git:''' Cloning a module of a git repository is done using any of the three protocols (git, https, or ssh). There is no need to worry about the protocol and git automatically takes care of it. Just follow the steps below:
+
  
In this lab, we will be cloning gnome-photos module as an example into the local workstation. All the changes we make to the source are maintained independent from the master copy using branches without messing up with the original source.
+
$ git pull
  
gnome-photos clone links:
+
Push: Uploads all the branch commits to remote URL.
• git://git.gnome.org/gnome-photos
+
  
• https://git.gnome.org/browse/gnome-photos
+
$ git push [alias] [branch]
  
• ssh://USERNAME@git.gnome.org/git/gnome-photos
+
Commit: commits file snapshots permanently to the version history.
  
Any of the above three URI’s can be used in the cloning process.
+
$ git commit –m “Commit message”
  
1. To clone a module from git central repository, we use the command “git clone”.
+
More git commands can be found here: https://git-scm.com/docs
  
$ git clone [git/ssh/https URI]
+
=== Directions ===
  
Note: git clone command clones the repository to the present working directory in the terminal.
+
'''Installation:'''
  
2. Once done, the source code of the cloned module can be viewed in the file system.
+
The git installation instructions for respective operating system can be found at:
  
 +
https://git-scm.com/downloads
  
Now that we had a copy of original source in our local workstation. Before making any changes to the source, it is a good idea to create a separate branch with the change_id so that we would not mess up with the master copy.
+
Below is the command to install git in fedora OS:
  
'''Creating a new branch with change_id:'''
+
$ yum install git
 +
 +
Once git has been installed, all the commands supported by git can be viewed by just typing git at the command line.
  
Now let’s create a new branch with CH_0001 as its name. $ git branch lists all the branches available. And to switch between different branches, we use the command $ git checkout [branch-name].
+
'''Configuration:'''
  
3.   List all the branches currently available using the following command:
+
The first thing we do after installation is introducing ourselves to git.
  
$ git branch
+
git config --global user.email "your Email"
 +
git config --global user.name "Your Name"
  
At the moment, we have only one branch i.e., master branch.
 
  
4.    Create a new branch using the command:
 
  
$ git branch CH_0001
+
'''Basic git usage:'''
  
This creates a new branch with name CH_0001, but we are still working on default (master) branch.
+
• Creating a repository:
  
5.  Check out CH_0001
+
mkdir GitSetUp
 +
cd GitSetUp
 +
git init
  
To make any changes to the new branch created, we need to open that branch for editing. This can be done using the command:
+
• Cloning a repository:
  
$ git checkout CH_0001
+
  git clone git@github.com:phacility/phabricator.git
  
The code is available to you to be changed.  
+
A repository can be newly created or cloned from other repository.
  
  
 +
Now that we created a repository to the client's machine. Now we can create/edit the files, then commit them.
  
'''Documentation:'''
+
• Creating new file and adding it to git:
  
Create a file in your favorite editor. Add all your screenshots and then answer the following questions in the next section in your file.
+
touch exampleFile.txt
Also, review the following rubric for generating and submitting your work. Once you are satisfied that your lab is complete, create a pdf file and name it FossCloneWithGitLab_yourlastnamefirstinitial.pdf. Upload to your course management system.
+
  git status
  
=== Deliverables: ===
+
The file sample.txt is not added to the tracking list of git. So even if we try to commit, this file will not be added to the repository. So to track this file, we add the file to the git stage.
Create a word document and include screenshots of different stages of installations in it. In addition, answer the questions.
+
  
 +
git add exampleFile.txt
 +
git status
  
'''Cloning Lab Rubric (100 points)'''
+
Now, the file sample.txt is added to the git stage and it will be tracked for any changes.
  
Screenshots of the above 5 steps (50 points)
+
• Committing the Changes:
  
Lab Questions (50 points)    • What is Git Server? (10 points)      • Name several free git servers for educational purposes. (10 points)      • Explain the importance of version control. (10 points)            •    What would the branch and checkout commands do ? (10 points) • Grammar, Spelling and Neatness (5 points) – named file correctly and uploaded properly on time. (5 points)
+
git commit -m "This is the commit message for tracking changes."
 +
  git status
  
 +
• Working with git branches:
  
=== Comments: ===
+
git branch
  
=== Additional Information: ===
+
Initially we only have one branch i.e, “master”. We would try to create a new branch named “bugfix_bugid”.
{| border="1"
+
 
|-
+
git branch bugfix_bugid
|'''Knowledge Area/Knowledge Unit''' || Cloning
+
git branch
|-
+
 
|'''Topic''' ||  
+
Now, we will try to create a new file newFile.txt and commit it.
|-
+
 
|'''Level of Difficulty''' ||
+
git commit -m "Here are the changes to fix the bug."
|-
+
 
|'''Estimated Time to Completion''' ||2 hours
+
The new file commit will only be committed to the branch bugfix_bugid as we are currently working in that branch.
|-
+
 
|'''Materials/Environment''' ||
+
  git checkout master
|-
+
git ls-files
|'''Author''' || Mohsen Dorodchi
+
  git checkout bugfix_bugid
|-
+
git ls-files
|'''Source''' ||
+
 
|-
+
Using branches, we can create multiple branches for each bugfix and then merge it to the master branch when done.
|'''License''' ||
+
 
|}
+
 
 +
'''Documentation:'''  
 +
 
 +
Create a file in your favorite editor. Add all your screenshots and then answer the following questions in the next section in your file.
 +
Also, review the following rubric for generating and submitting your work. Once you are satisfied that your lab is complete, create a pdf file and name it FossCloneWithGitLab_yourlastnamefirstinitial.pdf. Submit your work as indicated by your instructor (such as submitting into your course management system).
 +
 
 +
=== Deliverables ===
 +
 
 +
Create a document and include screenshots of different stages of installations in it.
 +
Make sure all screenshots are accompanied by proper captions and/or brief explanation as necessary.
 +
In addition, answer the questions.
 +
 
 +
 
 +
'''Cloning Lab Rubric (100 points)'''
 +
 
 +
Screenshots of the above 5 steps (50 points)
  
 +
Lab Questions (50 points)   
 +
• What is Git Server? (10 points)     
 +
• Name several free git servers for educational purposes. (10 points)     
 +
• Explain the importance of version control. (10 points)           
 +
• What would  the branch and checkout commands do ? (10 points)
 +
• Grammar, Spelling and Neatness (5 points) – named file correctly and uploaded properly on time. (5 points)
  
--------------------
+
=== Comments ===
  
 +
=== Additional Information ===
 +
{{Learning Activity Info
 +
|acm unit=
 +
SDF - Software Development Fundamentals, SE - Software Engineering
 +
|acm topic=
 +
Git Set up
 +
|difficulty=
 +
medium
 +
|time=
 +
2 hours
 +
|environment=
 +
|author=
 +
Mohsen Dorodchi
 +
|source=
 +
|license=
 +
}}
  
[[Category: Learning_Activity]]
+
[[Category:Learning Activity]]
[[Subcategory:Cloning]]
+
[[Category:CS2]]
 +
[[Category:Git]]
 +
[[Category:Good Draft]]

Latest revision as of 00:07, 8 September 2018


Title

Setting up Git Server

Overview

Git is an open source distributed version control system originally developed to support the development of the Linux kernel.

Using git clone [url] , you can clone a repository.

Every Git working directory is a full-fledged repository with complete history and full version tracking capabilities, not dependent on network access or a central server.

Prerequisites

Version Control/Repository

Learning
Objectives
After successfully completing this activity, the learner should be able to:
  • Set up Git
Process Skills
Practiced


Background

Version Control: A version control system is a repository of files that records the changes to a file or set of files often the files for the source code of computer programs, with monitored access. Every change made to the source is tracked, along with who made the change, why they made it, and references to problems fixed, or enhancements introduced, by the change so that you can recall specific versions later. In this lab we will be using a git version control system.

Git version control: git is an open source distributed version control system originally developed by Linus Torvalds to support the development of the Linux kernel. Every Git working directory is a full-fledged repository with complete history and full version tracking capabilities, not dependent on network access or a central server. Git can be used as a local version control system without having any central repository.

Some of the basic Git commands are listed here.

Clone: Downloads the project and its entire history.

$ git clone [url]

Branch: Lists/creates new branch

$ git branch [branch-name]

Checkout: Switches between branches / updates working directory.

$ git checkout [branch-name]

Pull: Fetches all the history and merge to working directory.

$ git pull

Push: Uploads all the branch commits to remote URL.

$ git push [alias] [branch]

Commit: commits file snapshots permanently to the version history.

$ git commit –m “Commit message”

More git commands can be found here: https://git-scm.com/docs

Directions

Installation:

The git installation instructions for respective operating system can be found at:

https://git-scm.com/downloads

Below is the command to install git in fedora OS:

$ yum install git

Once git has been installed, all the commands supported by git can be viewed by just typing git at the command line.

Configuration:

The first thing we do after installation is introducing ourselves to git.

git config --global user.email "your Email"
git config --global user.name "Your Name"


Basic git usage:

• Creating a repository:

mkdir GitSetUp
cd GitSetUp
git init

• Cloning a repository:

 git clone git@github.com:phacility/phabricator.git

A repository can be newly created or cloned from other repository.


Now that we created a repository to the client's machine. Now we can create/edit the files, then commit them.

• Creating new file and adding it to git:

touch exampleFile.txt
git status

The file sample.txt is not added to the tracking list of git. So even if we try to commit, this file will not be added to the repository. So to track this file, we add the file to the git stage.

git add exampleFile.txt
git status

Now, the file sample.txt is added to the git stage and it will be tracked for any changes.

• Committing the Changes:

git commit -m "This is the commit message for tracking changes."
git status

• Working with git branches:

git branch

Initially we only have one branch i.e, “master”. We would try to create a new branch named “bugfix_bugid”.

git branch bugfix_bugid
git branch

Now, we will try to create a new file newFile.txt and commit it.

git commit -m "Here are the changes to fix the bug."

The new file commit will only be committed to the branch bugfix_bugid as we are currently working in that branch.

git checkout master
git ls-files
git checkout bugfix_bugid
git ls-files

Using branches, we can create multiple branches for each bugfix and then merge it to the master branch when done.


Documentation:

Create a file in your favorite editor. Add all your screenshots and then answer the following questions in the next section in your file. Also, review the following rubric for generating and submitting your work. Once you are satisfied that your lab is complete, create a pdf file and name it FossCloneWithGitLab_yourlastnamefirstinitial.pdf. Submit your work as indicated by your instructor (such as submitting into your course management system).

Deliverables

Create a document and include screenshots of different stages of installations in it. Make sure all screenshots are accompanied by proper captions and/or brief explanation as necessary. In addition, answer the questions.


Cloning Lab Rubric (100 points)

Screenshots of the above 5 steps (50 points)

Lab Questions (50 points)

•	What is Git Server? (10 points)      
•	Name several free git servers for educational purposes. (10 points)      
•	Explain the importance of version control. (10 points)            
•	What would  the branch and checkout commands do ? (10 points) 
•	Grammar, Spelling and Neatness (5 points) – named file correctly and uploaded properly on time. (5 points)

Comments

Additional Information

ACM BoK
Area & Unit(s)

SDF - Software Development Fundamentals, SE - Software Engineering

ACM BoK
Topic(s)

Git Set up

Difficulty

medium

Estimated Time
to Complete

2 hours

Environment /
Materials
Author(s)

Mohsen Dorodchi

Source
License
Personal tools
Namespaces
Variants
Actions
Events
Learning Resources
HFOSS Projects
Evaluation
Navigation
Toolbox