User Tools

Site Tools


guides:software:git

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
guides:software:git [2021/09/16 18:00] – [Overview: What is git?] Fixed typos, minor wording issues. jhoggardguides:software:git [2022/08/02 11:59] (current) – external edit 127.0.0.1
Line 101: Line 101:
 ==== Server: GitLab, GitHub, etc ==== ==== Server: GitLab, GitHub, etc ====
  
-Create and clone+We can also work with a //remote// repository, which holds a copy of all our work on a server.  Common servers include GitHub and GitLab.
  
-Push and pull+The department maintains its own GitLab server at codestore.cs.edinboro.edu.  See your professor if you need to set up an account.
  
-Fork another repository+=== Create and clone === 
 + 
 +If you want to set up a remote repository on codestore, you can click the "New" button in the upper-left after you log in: 
 + 
 +You can select "Create a blank project", then fill in the name of your project, a description, set the privacy level, and create the project. 
 + 
 +Afterwards, you will see instructions for cloning your repository to your local machine, but it is not hard: On your project's main page, click the "Clone" button and select the https address to copy. (There is a button that will copy it.) 
 + 
 +Then on your machine (possibly cslab103), type the following in the directory where you want to clone the repository: 
 +<code> 
 +git clone <address> 
 +</code> 
 +where ''<address>'' is the https address you copied from codestore.  (The repository will be copied into a directory named for the repo.) 
 + 
 +Now you have a local copy of the repository, and by default, it is connected to the remote repository.  (The remote repository gets the nickname ''origin''.)  You can work on your local copy, committing files as usual. 
 + 
 +However, ''origin'' doesn't know about the commits on your local machine, and your local repository won't know about any updates to ''origin'' until you //push// or //pull// them. 
 + 
 +=== Push and Pull === 
 + 
 +To send your commits up to ''origin'' (the remote repo) you need to //push// the files: 
 +<code> 
 +git push origin master 
 +</code> 
 +(The above sends your //master// branch commits to ''origin'' In our case, ''origin'' is the remote repository at codestore.) 
 + 
 +To update your local repository with any changes added to the remote repository, you need to //pull// the files.  (Or //fetch// them.)  The easiest way to update your local repository is to type  
 +<code> 
 +git pull 
 +</code> 
 +This will fetch any commits made on your current branch (probably master) and merge them into your current directory. 
 + 
 +You can also separate this into two steps. The first retrieves any new snapshots on the remote repository, and the second merges the changes into your current files. 
 +<code> 
 +git fetch 
 +git merge 
 +</code> 
 + 
 +==== Fork Another Repository ==== 
 + 
 +You may sometimes want to copy someone else's repository on codestore into your very own version of the repository.  This is called a //fork// (For example, your professor might provide you a basic repository for an assignment, and ask you to fork it so you can work on your own copy.) 
 + 
 +In GitLab (for example, at codestore), you can click on the "Fork" button at the top of a repository to make your own copy: 
 + 
 +Then you can clone //your// fork of the project to your own computer, and proceed as usual.
  
-=== Setting up SSH Credentials === 
  
 ==== Setting Options ==== ==== Setting Options ====
Line 117: Line 160:
 The following are common tasks to complete using git. Where we refer to GitLab, the same task can be completed with other git servers, such as GitHub, usually with very little or no change. The following are common tasks to complete using git. Where we refer to GitLab, the same task can be completed with other git servers, such as GitHub, usually with very little or no change.
  
-  * ''fork'': Make your own copy of someone else's repository on GitLab. +  * ''fork'': Make your own copy of someone else's repository on GitLab.\\ This is done on a GitLab web page by clicking the "fork" button
-  * ''clone'': Copy a GitLab archive to your personal computer. +  * ''clone'': Copy a GitLab archive to your personal computer. \\ Usage: ''git clone <address>'' 
-  * ''init'': Initialize a new git repository on your own computer. (Will not be connected to a server.) +  * ''init'': Initialize a new git repository on your own computer. (Will not be connected to a server, but it is possible to add one later.) \\ Usage: ''git init''. 
-  * ''status'': Show what files are untracked, changed, staged, etc., in the current local repository. +  * ''status'': Show what files are untracked, changed, staged, etc., in the current local repository.  \\ Usage: ''git status'' 
-  * ''add'': Add files to your local staging area. +  * ''add'': Add files to your local staging area. \\ Usage: ''git add <filename>'' 
-  * ''commit'': Move files from the staging area to your local repository. +  * ''commit'': Move files from the staging area to your local repository. \\ Usage: ''git commit -m "Commit message"'' \\ If the ''-m "Commit message"'' is left out, an editor will open for you write your commit message
-  * ''pull'': Update your local archive with changes/additions made to the server. (Assumes that you have an "upstream" repository on a server to pull from.) +  * ''pull'': Update your local archive with changes/additions made to the server. (Assumes that you have an "upstream" repository on a server to pull from.) \\ Usage: ''git pull'' 
-  * ''push'': Push changes in your local repository upstream to the server repository.  (Assumes that you have an "upstream" repository on a server to pull from.) +  * ''push'': Push changes in your local repository upstream to the server repository.  (Assumes that you have an "upstream" repository on a server to pull from.  \\ Usage: ''git push'' For more control, use ''git push origin <branchname>'' 
-  * ''log'': See a list of commits made to your repository. +  * ''log'': See a list of commits made to your repository.  \\ Usage: ''git log'' 
-  * ''checkout'': Switch to a new branch. +  * ''checkout'': Switch to a new branch.  \\ Usage: ''git checkout <branchname>'' 
-  * ''diff'': See differences between various branches.+  * ''diff'': See differences between various branches.  \\ Usage: ''git diff'' for the difference between current files and last commit.  \\ ''git diff <branchname>'' compares to another branch.
  
  
guides/software/git.1631815217.txt.gz · Last modified: 2022/08/02 11:59 (external edit)