Git
1) Source Control
a) Centralized
- Free: Subversion, CVS
- Commercial: ClearCase, Perforce, team Foundation Server (TFS)
- Requieres connection to central server for most operations
b) Decentralized / Distributed
- Mercural (Hg)
- Git
- Most operations are local
- Central server not required
2) Git overview
- Distributed source control system, not required to be decentralized
- massively scales
- open source
- developed for Linux project requirements
- most operations are local
- very fast
- active community
- Most popular DVCS, VCS
3) Key Concepts
- Repository contains files, history, config managed by Git
- Three State of Git
* working directory - is a directory or folder on your computer
* staging area - pre-commit holding area
* commit - Git Repository (history)
Basic Git Workflow Life Cycle
a) Local
-Working Directory - is the directory or folder on your computer, that holds all the project or application files. Files within working directory , may or may not be managed by Git. However Git is aware of them. Normally, within the working directory is a hidden falder called the ".git"
-Staging Area - In between is the Git staging area, often reffered to as the Git index , that is a holding area for queueing up changes for the next commit.. Since files in the staging area have not beeen commited yet, you can move the files in and out of the staging area without impacting the Git repository, and the history of changes
-Repository (.git folder) - contains actual git repository. The Git repository manages the Git commit history - that is all changes that are finalized and permanently part of the Git repository.
b) Remote
c) master branch
4) Git installation and Setup
5) The Basic Commands
git version
git config --global user.name "Name Surname"
git config --global user.email "email@address"
git config --global --list
git clone <repository address>
git status # command to see if there are any changes between the working directory, the staging area, our local repository, and our remote repository
git add start.txt # put file start.txt to staging area
git commit -m "commit message" #we are back in clean working directory state, and that our master branch is ahead of "origin/master" by one commit. So, now the new file has been moved from staging area into the local repository
git push origin master #
origin - refers to the GitHub copy of our repository
vim ~/.gitconfig
[user]
name = Name Surname
email = email@adress
git config --global core.editor "notepad++.exe -multiInst -nosession" #
git config --global -e # running config from editor
6) Comparing
7) Branching and Merging
8) GitHub Introduction
9) Tools Setup (Text Editor, Compare / Merge Tool)
10) Starting a Project
a) Fresh (not source yet)
git init fresh-project
cd fresh-project
cd .git # local repository
b) Existing source locally
git init
git add .
git commit -m "commit message"
c) Github project (Fork and clone)
git clone <url>
11) Basic Workflow (add, commit, push & pull)
12) Working with Files (rename, move & delete)
13) History and Aliases
git help log
14) Ignoring Unwanted Files
15) Recursive Add
git add .
16) Backing Out Changes
git checkout -- <file> ... #to discard changes in working directory
17) moving files in git directory
git mv file1.txt file2.txt
git add -A# will recursively add any changes, but it will also update any files that have been renamed, moved or deleted
18) Deleting files
git rm file.txt
19) Restoring files
a)
git rm file.txt
-file is no longer in local directory but git status shows that the deletion is currently staged . That means the file has not been permanently deleted, at least as far as git is concerned. To get ready to delete the file it has to be unstaged.
git reset HEAD filename.txt
- if you ls file is not in the directory. So the previous command , the "reset HEAD" specifing th file, just unstaged the deletion, it did not actually restorethe file back to the filesystem. So effectivaly , we need to discard whatever temporary changes we have made to the working directory by using git checkout command.
git checkout -- filename.txt
-
b)
rm filename.txt
git add -A # will add and update any changes to the working directory, including renames and deletion staged.
git commit -m "deleted filename.txt file" #
20) Listing files
git ls-files
20) History
git log
21)
22)
23)
24)
25)
26)
27)
28)
29)
30)
31)
32)
33)
a) Centralized
- Free: Subversion, CVS
- Commercial: ClearCase, Perforce, team Foundation Server (TFS)
- Requieres connection to central server for most operations
b) Decentralized / Distributed
- Mercural (Hg)
- Git
- Most operations are local
- Central server not required
2) Git overview
- Distributed source control system, not required to be decentralized
- massively scales
- open source
- developed for Linux project requirements
- most operations are local
- very fast
- active community
- Most popular DVCS, VCS
3) Key Concepts
- Repository contains files, history, config managed by Git
- Three State of Git
* working directory - is a directory or folder on your computer
* staging area - pre-commit holding area
* commit - Git Repository (history)
Basic Git Workflow Life Cycle
a) Local
-Working Directory - is the directory or folder on your computer, that holds all the project or application files. Files within working directory , may or may not be managed by Git. However Git is aware of them. Normally, within the working directory is a hidden falder called the ".git"
-Staging Area - In between is the Git staging area, often reffered to as the Git index , that is a holding area for queueing up changes for the next commit.. Since files in the staging area have not beeen commited yet, you can move the files in and out of the staging area without impacting the Git repository, and the history of changes
-Repository (.git folder) - contains actual git repository. The Git repository manages the Git commit history - that is all changes that are finalized and permanently part of the Git repository.
b) Remote
c) master branch
4) Git installation and Setup
5) The Basic Commands
git version
git config --global user.name "Name Surname"
git config --global user.email "email@address"
git config --global --list
git clone <repository address>
git status # command to see if there are any changes between the working directory, the staging area, our local repository, and our remote repository
git add start.txt # put file start.txt to staging area
git commit -m "commit message" #we are back in clean working directory state, and that our master branch is ahead of "origin/master" by one commit. So, now the new file has been moved from staging area into the local repository
git push origin master #
origin - refers to the GitHub copy of our repository
vim ~/.gitconfig
[user]
name = Name Surname
email = email@adress
git config --global core.editor "notepad++.exe -multiInst -nosession" #
git config --global -e # running config from editor
6) Comparing
7) Branching and Merging
8) GitHub Introduction
9) Tools Setup (Text Editor, Compare / Merge Tool)
10) Starting a Project
a) Fresh (not source yet)
git init fresh-project
cd fresh-project
cd .git # local repository
b) Existing source locally
git init
git add .
git commit -m "commit message"
c) Github project (Fork and clone)
git clone <url>
11) Basic Workflow (add, commit, push & pull)
12) Working with Files (rename, move & delete)
13) History and Aliases
git help log
14) Ignoring Unwanted Files
15) Recursive Add
git add .
16) Backing Out Changes
git checkout -- <file> ... #to discard changes in working directory
17) moving files in git directory
git mv file1.txt file2.txt
git add -A# will recursively add any changes, but it will also update any files that have been renamed, moved or deleted
18) Deleting files
git rm file.txt
19) Restoring files
a)
git rm file.txt
-file is no longer in local directory but git status shows that the deletion is currently staged . That means the file has not been permanently deleted, at least as far as git is concerned. To get ready to delete the file it has to be unstaged.
git reset HEAD filename.txt
- if you ls file is not in the directory. So the previous command , the "reset HEAD" specifing th file, just unstaged the deletion, it did not actually restorethe file back to the filesystem. So effectivaly , we need to discard whatever temporary changes we have made to the working directory by using git checkout command.
git checkout -- filename.txt
-
b)
rm filename.txt
git add -A # will add and update any changes to the working directory, including renames and deletion staged.
git commit -m "deleted filename.txt file" #
20) Listing files
git ls-files
20) History
git log
21)
22)
23)
24)
25)
26)
27)
28)
29)
30)
31)
32)
33)
Komentarze
Prześlij komentarz