Git: Working with Remotes from the Command Line

(Difference between revisions)
Jump to: navigation, search
(Background:)
(Directions:)
Line 85: Line 85:
 
• Creating a repository:
 
• Creating a repository:
  
mkdir GitSetUp
+
mkdir GitSetUp
 
+
cd GitSetUp
cd GitSetUp
+
git init
 
+
git init
+
  
 
• Cloning a repository:
 
• Cloning a repository:
  
git clone git@github.com:phacility/phabricator.git
+
git clone git@github.com:phacility/phabricator.git
  
 
A repository can be newly created or cloned from other repository.
 
A repository can be newly created or cloned from other repository.
Line 102: Line 100:
 
Creating new file and adding it to git:
 
Creating new file and adding it to git:
  
touch exampleFile.txt
+
touch exampleFile.txt
 
+
git status
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.
 
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 add exampleFile.txt
 
+
git status
git status
+
  
 
Now, the file sample.txt is added to the git stage and it will be tracked for any changes.
 
Now, the file sample.txt is added to the git stage and it will be tracked for any changes.
Line 116: Line 112:
 
'''Committing the changes:'''
 
'''Committing the changes:'''
  
git commit -m "This is the commit message for tracking changes."
+
git commit -m "This is the commit message for tracking changes."
 
+
git status
git status
+
  
 
'''Working with git branches:'''
 
'''Working with git branches:'''
  
git branch
+
git branch
  
 
Initially we only have one branch i.e, “master”. We would try to create a new branch named “bugfix_bugid”.
 
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 bugfix_bugid
 
+
git branch
git branch
+
  
 
Now, we will try to create a new file newFile.txt and commit it.
 
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."
+
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.
 
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 checkout master
 
+
git ls-files
git ls-files
+
git checkout bugfix_bugid
 
+
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.
 
Using branches, we can create multiple branches for each bugfix and then merge it to the master branch when done.
Line 150: Line 141:
  
 
Create a file in your favorite editor. Add all your screenshots and then answer the following questions in the next section in your file.
 
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.
+
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: ===
 
=== Deliverables: ===

Revision as of 03:55, 10 November 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/Repository
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. Submit your work as indicated by your instructor (such as submitting into 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 Git Set up
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