Difference between revisions of "Git manual"
Line 1: | Line 1: | ||
+ | ==Documentation== | ||
+ | Git official documentation - https://git-scm.com/doc | ||
+ | |||
+ | GitHub cheatsheet - https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf | ||
+ | |||
==Downloading Git== | ==Downloading Git== | ||
https://git-scm.com/downloads | https://git-scm.com/downloads | ||
Line 22: | Line 27: | ||
As a result the repository is cloned into the local directory C:\workspace\iag0581 and we can change also our current directory to it by typing: | As a result the repository is cloned into the local directory C:\workspace\iag0581 and we can change also our current directory to it by typing: | ||
<source lang="bash" collapse="false">cd iag0581</source> | <source lang="bash" collapse="false">cd iag0581</source> | ||
+ | |||
+ | ===Staging area=== | ||
+ | Next we can start adding files for version control. Let's say that we already have some files in another directory (C:\workspace\lab1) that we wish to add to version control. For copying files in terminal there is a command '''cp'''. | ||
+ | <source lang="bash" collapse="false">cp C:\workspace\lab1 C:\workspace\iag0581 -rf</source> | ||
+ | To make sure that the files copied over successfully we can see the contents of the current directory by entering command '''ls'''. | ||
+ | Next we have to notify git that we have files that we wish to add to version control. Git has so called staging area, which is used to temporarily hold, prepare and review changes to be made. To add files into the staging area, command '''git add <filename>''' is used. So if we wish to add the previously copied folder, type: | ||
+ | <source lang="bash" collapse="false">git add lab1</source> | ||
+ | To see all the files in the staging area for making sure we are ready to commit the changes, there is a command '''git status''' which lists all the new and modified files to be committed. | ||
+ | ===Committing=== | ||
+ | Before committing it is required to set up your name and e-mail with git. To do that there are following commands that should be inserted: | ||
+ | <source lang="bash" collapse="false"> | ||
+ | git config --global user.email "you@example.com" | ||
+ | git config --global user.name "Your Name" | ||
+ | </source> | ||
+ | Next we can commit the changes with the command: | ||
+ | <source lang="bash" collapse="false">git commit -m "your comment about the commit"</source> | ||
+ | ===Pushing=== | ||
+ | Now that the changes are stored locally we may want to push the changes back to remote repository also. To do that there is the command '''git push''' | ||
+ | <source lang="bash" collapse="false">git push origin master</source> | ||
+ | Origin and master specify to which remote repository and branch the commit will be pushed into. | ||
+ | Next your username and password will be asked. (The same username and password that you use for logging in to the lab computers). | ||
+ | ===Pulling=== | ||
+ | For the next scenario, let's say that we have repositories cloned locally to both lab computer and computer at home |
Revision as of 11:01, 25 August 2015
Contents
Documentation
Git official documentation - https://git-scm.com/doc
GitHub cheatsheet - https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf
Downloading Git
When installing Git on Windows operating system, installation settings can be set as default. (Use Git from Git Bash only; Checkout Windows-style, commit Unix-stile line endings; Use MinTTY)
Getting started
Each student has already a repository generated beforehand. For example:
https://git.ttu.ee/kursused/iag0581/firstname.lastname.git
For authentication your UNI-ID will be used. (The same username and password that you use for logging in to the lab computers).
Assuming that Git is successfully installed, in Windows open start menu and search for Git Bash and open it. In Linux or Mac simply open terminal.
Cloning
Let's say that we want to clone the repository to our local directory at C:\workspace. First we have to change the current directory by typing to terminal:
cd /c/workspace
For cloning the existing repository from https://git.ttu.ee/kursused/iag0581/firstname.lastname.git, type in:
git clone https://git.ttu.ee/kursused/iag0581/firstname.lastname.git iag0581
As a result the repository is cloned into the local directory C:\workspace\iag0581 and we can change also our current directory to it by typing:
cd iag0581
Staging area
Next we can start adding files for version control. Let's say that we already have some files in another directory (C:\workspace\lab1) that we wish to add to version control. For copying files in terminal there is a command cp.
cp C:\workspace\lab1 C:\workspace\iag0581 -rf
To make sure that the files copied over successfully we can see the contents of the current directory by entering command ls. Next we have to notify git that we have files that we wish to add to version control. Git has so called staging area, which is used to temporarily hold, prepare and review changes to be made. To add files into the staging area, command git add <filename> is used. So if we wish to add the previously copied folder, type:
git add lab1
To see all the files in the staging area for making sure we are ready to commit the changes, there is a command git status which lists all the new and modified files to be committed.
Committing
Before committing it is required to set up your name and e-mail with git. To do that there are following commands that should be inserted:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
Next we can commit the changes with the command:
git commit -m "your comment about the commit"
Pushing
Now that the changes are stored locally we may want to push the changes back to remote repository also. To do that there is the command git push
git push origin master
Origin and master specify to which remote repository and branch the commit will be pushed into. Next your username and password will be asked. (The same username and password that you use for logging in to the lab computers).
Pulling
For the next scenario, let's say that we have repositories cloned locally to both lab computer and computer at home