Git: Working with Remotes from the Command Line

(Difference between revisions)
Jump to: navigation, search
Line 2: Line 2:
 
{| border="1"
 
{| border="1"
 
|-  
 
|-  
|'''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.
 +
 +
 +
 +
 +
 +
|-
 +
|'''Prerequisite Knowledge''' ||Version Control/Re
 +
 +
|-
 +
|'''Learning Objectives''' ||Setting up Git   
 +
|}
 +
 +
=== Background: ===
 
Version Control:
 
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.
 
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.
Line 15: Line 31:
 
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.
+
$ git checkout [branch-name]
After logging in to the Virtual Machine using the user credentials created during installation, open terminal program as shown below.
+
 
 +
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
  
1. Click on “Activities” on the top left and type “Terminal” in the search bar.
 
  
2. Now click on the Terminal Button displayed in the search results and type the command “git” in the command line.
 
Please refer to https://git-scm.com/docs for getting familiar with all the git commands available.
 
 
=== Directions: ===
 
=== 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:
+
'''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.
 +
 
  
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.
+
Now that we created a repository to the client's machine. Now we can create/edit the files, then commit them.
  
gnome-photos clone links:
+
Creating new file and adding it to git:
git://git.gnome.org/gnome-photos
+
  
• https://git.gnome.org/browse/gnome-photos
+
touch exampleFile.txt
  
• ssh://USERNAME@git.gnome.org/git/gnome-photos
+
git status
  
Any of the above three URI’s can be used in the cloning process.
+
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.
  
1. To clone a module from git central repository, we use the command “git clone”.
+
git add exampleFile.txt
  
$ git clone [git/ssh/https URI]
+
git status
  
Note: git clone command clones the repository to the present working directory in the terminal.
+
Now, the file sample.txt is added to the git stage and it will be tracked for any changes.
  
2. Once done, the source code of the cloned module can be viewed in the file system.
+
'''Committing the changes:'''
  
 +
git commit -m "This is the commit message for tracking changes."
  
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.
+
git status
  
'''Creating a new branch with change_id:'''
+
'''Working with git branches:'''
  
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].
+
git branch
  
3.   List all the branches currently available using the following command:
+
Initially we only have one branch i.e, “master”. We would try to create a new branch named “bugfix_bugid”.
  
$ git branch
+
git branch bugfix_bugid
  
At the moment, we have only one branch i.e., master branch.
+
git branch
  
4.    Create a new branch using the command:
+
Now, we will try to create a new file newFile.txt and commit it.
  
$ git branch CH_0001
+
git commit -m "Here are the changes to fix the bug."
  
This creates a new branch with name CH_0001, but we are still working on default (master) branch.  
+
The new file commit will only be committed to the branch bugfix_bugid as we are currently working in that branch.
  
5.  Check out CH_0001
+
git checkout master
  
To make any changes to the new branch created, we need to open that branch for editing. This can be done using the command:
+
git ls-files
  
$ git checkout CH_0001
+
git checkout bugfix_bugid
  
The code is available to you to be changed.
+
git ls-files
  
 +
Using branches, we can create multiple branches for each bugfix and then merge it to the master branch when done.
  
  

Revision as of 02:59, 30 September 2015

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.



Prerequisite Knowledge Version Control/Re
Learning Objectives Setting up Git

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. Upload to your course management system.

Deliverables:

Create a word document and include screenshots of different stages of installations in it. 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:

Knowledge Area/Knowledge Unit Cloning
Topic
Level of Difficulty
Estimated Time to Completion 2 hours
Materials/Environment
Author Mohsen Dorodchi
Source
License



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