A distributed revision control system

Github Desktop

Simple collaboration from your desktop

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

Made with Slides.com