A distributed revision control system
Source code management system for software development.
Maintaining versions of applications when these have a large number of source files.
SourceTree
SourceTree is a free Git Client that provides a graphical interface for Git repositories.
Terms
- Repository: A repository is a collection of commits,
- Index or Staging Area: changes are first registered in something called the index or stage.
- Working Tree or Working Directory: A working tree is any directory on your file system which has a repository associated with it.
- Commit: A commit is a snapshot of your working tree at some point in time.
Terms
- Branch: A branch is just a name for a commit. It’s the parentage of a commit which defines its history.
- Tag: A tag is also a name for a commit, similar to a branch, except that it always names the same commit.
- Master: the mainline of development in most repositories is done on a branch called “master”.
-
HEAD: refers to the last commit or branch you checked out.
Initializing
From existing data
cd ~/projects/myproject
git init
git add .
From existing repo
git clone ~/existing/repo ~/new/repo
git clone git://host.org/project.git
git clone ssh://you@host.org/proj.git
Git Config
From existing data
cd ~/projects/myproject
git config user.name <name>
git config user.email <email>
git remote add origin https://jeanpaul4289@bitbucket.org/jeanpaul4289/probando.git
git add .
git commit -m "Todo"
git push -u origin --all # pushes up the repo and its refs for the first time
git push -u origin --tags # pushes up any tags
git init
git status
git add .
git status
git commit -m "Add files"
git add "*.txt"
git commit -m 'Add all txt files'
git log
git remote add origin https://github.com/try-git/try_git.git
git push -u origin master
git pull origin master
git diff HEAD
git add octofamily/octodog.txt
git diff --staged
git reset octofamily/octodog.txt
git checkout -- octocat.txt
git branch clean_up
git checkout clean_up
git rm '*.txt'
git commit -m 'Remove all txt files'
git checkout master
git merge clean_up
git branch -d clean_up
git push
Checking the status
Files changed in working directory
git status
Changes to tracked files
git diff
What changed between $ID1 and $ID2
git diff $id1 $id2
History of changes
git log
History of changes for file with diffs
git log -p $file $dir/dir/ec/tory
Who changed what and when in a file
git blame $file
A commit identified by $ID
git show $id
A specific file from a specific $ID
git show $id:$file
All local branches
git branch
All files from a specific commit
git diff-tree --no-commit-id --name-only -r <commit-ish>
$id: represent either a commit id, branch or a tag name
$file: arbitrary file name
$branch: arbitrary branch name
Tracking Files
Add file contents to the index
git add $files
Move or rename a file, a directory or a symlink
git mv $old $new
Remove files from the working tree and from the index
git rm $files
git rm --cached $files
$files: arbitrary file name
--cached: use this option to unstage and remove paths only from the index
Revert
Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded
git reset --hard (NO UNDO) (throw away all pending changes)
Revert some existing commits
git revert $id
Replace previous commits, Fix the last commit
git commit -a --amend
Switch branches or restore working tree files, Checkout the $id version of a file
git checkout $id $file
$id: represent either a commit id, branch or a tag name
$file: arbitrary file name
In Git, reverting usually means adding a commit that undos changes in previous commits.
Update
Fetch latest changes from origin (this does not merge them)
git fetch
Pull latest changes from origin (does a fetch followed by a merge)
git pull
Apply a patch that some sent you
git am -3 patch.mbox (in case of a conflict, resolve and use git am --resolved)
git apply patch.diff
Branch
Switch to the $id branch
git checkout $id
Merge branch1 into branch2
git checkout $branch2
git merge $branch1
Create branch named $branch based on the HEAD
git branch $branch
Delete branch $branch
git branch -d $branch
$ref: an object hash or name
$file: arbitrary file name
Publish
Commit all your local changes
git commit -a (-a: add changed files automatically)
Prepare a patch for other developers
git format-patch origin (create set of diffs)
Push changes to origin
git push
Mark a version / milestone
git tag v1.0
$ref: an object hash or name
$file: arbitrary file name
Commands Sequence
GIT Commands (Sourcetree)
By Jean Paul Demorizi
GIT Commands (Sourcetree)
- 1,537