Felipe Fonseca Rocha
Curioso por natureza e grande apreciador de novos conhecimentos, independente da disciplina!
Estrutura inicial
Pastas?
Hooks?
$ git init
$ tree .git/
.git/
├── HEAD
├── config
├── description
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ ├── pre-receive.sample
│ ├── prepare-commit-msg.sample
│ └── update.sample
├── info
│ └── exclude
├── objects
│ ├── info
│ └── pack
└── refs
├── heads
└── tags
40-character checksum (SHA-1)
2 - directory name
38 - file (object) name
$ touch index.php
<?php
echo "Hello World";
$ touch README.md
# Description
This is my hello world project
$ git add .
$ git commit -m "Initial Commit"
//UPDATED STRUCTURE
├── objects
│ ├── 5d
│ │ └── 92c127156d3d86b70ae41c73973434bf4bf341
│ ├── a6
│ │ └── dbf05551541dc86b7a49212b62cfe1e9bb14f2
│ ├── cf
│ │ └── 59e02c3d2a2413e2da9e535d3c116af1077906
│ ├── f8
│ │ └── 9e64bdfcc08a8b371ee76a74775cfe096655ce
│ ├── info
│ └── pack
$ touch index.php
<?php
echo "Hello World";
$ touch README.md
# Description
This is my hello world project
$ git add .
$ git commit -m "Initial Commit"
# Cloning from known source
git clone ssh://ex@example.com/path/my-project.git
cd my-project
# Start working on the project
# Cloning alternatives
git clone <repo> <directory>
git clone --branch <tag> <repo>
git clone -depth=1 <repo>
git clone -branch new_feature git://remrepository.git
# Initialize a empty repo
git init --bare <directory>
# Initialize a empty repo with tamplate
git init <directory> --template=<template_directory>
# Initilize a remote empity repo
ssh <user>@<host> cd path/repo git init --bare my-project.git
# Configure commit account
git config --global user.email "your_email@example.com"
git config --global user.name "Your Name"
# Configure git repo account
git config --global github.user myusername
git config --global github.token mytoken
# Git config levels
git config --local <repo>/.gitconfig
git config --global <home>/.gitconfig
git config --system <program>/.gitconfig
# Git add files to next commit -
# add files that are untracked (git control)
git add <file/directory>
# Git add all files changed that
# are not in .gitignore
git add -a
# Git interative add session
git add -p
# Git commit
git commit
# Git with message
git commit -m "message here"
# Git add all files and add message
git commit -a -m "message here"
# Git change last commit
git commit --amend
# Git list all stashes and positions
git stash list
# Git add all changed andtracked files
# to stash and reset branch
git stash
# Git re-apply last stash
git stash pop
# Git re-apply a specific stash
git stash pop stash@{2}
# Git re-apply a stash without removing it
git stash apply
# Git clear all stashes
git stash clear
Command | Description |
---|---|
/ | search for a hunk by regex |
? | help |
n | don't stash this hunk |
q | quit (any hunks that have already been selected will be stashed) |
s | split this hunk into smaller hunks |
y | stash this hunk |
# Git update remote connection
git fetch <remote>
# Git update a specific branch
git fetch <remote> <branch>
# Git update entire repo
git fetch --all
# Git update Example
git fetch origin[
# >>>Result
a1e8fb5..45e66a4 master -> origin/master
a1e8fb5..9e8ab1c develop -> origin/develop
* [new branch] some-feature -> origin/some-feature
# Git update remote connection
git pull <remote>
# Default behavior
git pull # = git fetch origin HEAD && git merge HEAD
# Git update a specific branch
git pull <remote> <branch>
# Git update without merge commit
git pull --no-commit <remote>
# Git rebase branch
git pull --rebase <remote>
# Git output steps
git pull --verbose
# Git config rebase as default behaviour
git config --global branch.autosetuprebase always
# Git list branches
git branch
# Git create branch
git branch <feature>
# Git safe deletion
git branch -d <branch>
# Git unsafe deletion
git branch -D <branch>
# Git rename brnach
git branch -m <branch>
# Git list all branches
git branch -a
# Git change branch
git checkout <branch>
# Git create and change branch
git checkout -b <branch>
git checkout -b <new-branch> <existing-branch>
# Git reset local branch to last commit
git checkout .
# Git reset a file (remove from "add")
git checkout <path>/<file>
# Git fast foward | 3 way
git merge <branch>
# Git non fast foward
git merge --no-ff <branch>
Git push:
# Git update remote with commit
git push <remote> <branch>
# Git update remote directly
git push
# Push withou care a local branch
git push <remote> --force
# Push all local branchs
git push <remote> --all
# Push local branch to remote with tag
git push <remote> --tags
# Git change base
git rebase <base>
# Git rebase continue solving conflicts
git rebase --continue
# Git abort rebase operation
git rebase --abort
# Git rebase more than one branch
git rebase --onto master featureA featureB
Um dos fluxos possíveis
Apresenta um plugin para git
benefícios de organização
## criação de uma nova branch para desenvolvimento de feature
git fetch
git checkout demanda-sprint3
git pull
git checkout -b "feature-que-vc-vai-desenvolver"
## alterações na branch
git add . # arquivos que serão adicionado e que
# (se necessário) já foram excluídos no .gitignore
git commit -a -m "Mensgaem de um comite qua não adicionou novos arquivos"
## alterações mínimas na sua branch
git commit -a -m "Mensgaem de um comite qua não adicionou novos arquivos"
#alterações que não precisam de uma nova branch
git pull --rebase
## alterações na sua branch
git fetch
git checkout "feature-que-vc-esta-desenvolvendo"
git rebase origin/demanda-sprint3
git checkout demanda-sprint3
git merge "feature-que-vc-esta-desenvolvendo" --ff
By Felipe Fonseca Rocha
Git Ingnition presentation for DTI new members. An align of concepts and first steps.
Curioso por natureza e grande apreciador de novos conhecimentos, independente da disciplina!