Skip to content

Commit b7d6c19

Browse files
authored
Merge pull request arslanbilal#61 from samundra/update-infos
add git-flow-avh, update git branch informations
2 parents d063918 + 39590fc commit b7d6c19

File tree

1 file changed

+73
-26
lines changed

1 file changed

+73
-26
lines changed

README.md

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Git and Git Flow Cheat Sheet [![Awesome](https://cdn.rawgit.com/sindresorhus/awe
22
===============
33
<hr>
44
<p align="center">
5-
<img alt="Git" src="./Img/git-logo.png" height="190" width="455">
5+
<img alt="Git" src="./Img/git-logo.png" height="190" width="455">
66
</p>
77
<hr>
88

@@ -167,7 +167,7 @@ $ git commit -am 'message here'
167167

168168
##### Commit to some previous date:
169169
```
170-
git commit --date="`date --date='n day ago'`" -am "Commit Message"
170+
$ git commit --date="`date --date='n day ago'`" -am "<Commit Message Here>"
171171
```
172172

173173
##### Change last commit:<br>
@@ -177,31 +177,45 @@ git commit --date="`date --date='n day ago'`" -am "Commit Message"
177177
$ git commit -a --amend
178178
```
179179

180+
##### Amend with last commit but use the previous commit log message
181+
<em><sub>Don't amend published commits!</sub></em>
182+
183+
```shell
184+
$ git commit --amend --no-edit
185+
```
186+
180187
##### Change committer date of last commit:
181188
```
182189
GIT_COMMITTER_DATE="date" git commit --amend
183190
```
184191

185192
##### Change Author date of last commit:
186-
```
187-
git commit --amend --date="date"
193+
```shell
194+
$ git commit --amend --date="date"
188195
```
189196

190197
##### Move uncommitted changes from current branch to some other branch:<br>
191198
```
192-
git stash
193-
git checkout branch2
194-
git stash pop
199+
$ git stash
200+
$ git checkout branch2
201+
$ git stash pop
195202
```
196203

197204
##### Restore stashed changes back to current branch:
205+
```shell
206+
$ git stash apply
198207
```
199-
git stash apply
208+
209+
#### Restore particular stash back to current branch:
210+
- *{stash_number}* can be obtained from `git stash list`
211+
212+
```shell
213+
$ git stash apply stash@{stash_number}
200214
```
201215

202216
##### Remove the last set of stashed changes:
203217
```
204-
git stash drop
218+
$ git stash drop
205219
```
206220

207221
<hr>
@@ -254,7 +268,7 @@ $ git blame <file>
254268

255269
##### Show Reference log:
256270
```
257-
$ git reflog show
271+
$ git reflog show
258272
```
259273

260274
##### Delete Reference log:
@@ -270,6 +284,11 @@ $ git reflog delete
270284
$ git branch
271285
```
272286

287+
#### List local/remote branches
288+
```
289+
$ git branch -a
290+
```
291+
273292
##### List all remote branches:
274293
```
275294
$ git branch -r
@@ -280,11 +299,21 @@ $ git branch -r
280299
$ git checkout <branch>
281300
```
282301

302+
##### Checkout single file from different branch
303+
```
304+
$ git checkout <branch> -- <filename>
305+
```
306+
283307
##### Create and switch new branch:
284308
```
285309
$ git checkout -b <branch>
286310
```
287311

312+
#### Checkout and create a new branch from existing commit
313+
```
314+
$ git checkout <commit-hash> -b <new_branch_name>
315+
```
316+
288317
##### Create a new branch based on your current HEAD:
289318
```
290319
$ git branch <new-branch>
@@ -300,6 +329,11 @@ $ git branch --track <new-branch> <remote-branch>
300329
$ git branch -d <branch>
301330
```
302331

332+
##### Rename current branch to new branch name
333+
```shell
334+
$ git branch -m <new_branch_name>
335+
```
336+
303337
##### Force delete a local branch:
304338
<em><sub>You will lose unmerged changes!</sub></em>
305339

@@ -352,7 +386,7 @@ $ git pull origin master
352386

353387
##### Get all changes from HEAD to local repository without a merge:
354388
```
355-
git pull --rebase <remote> <branch>
389+
$ git pull --rebase <remote> <branch>
356390
```
357391

358392
##### Publish local changes on a remote:
@@ -363,8 +397,10 @@ $ git push remote <remote> <branch>
363397
##### Delete a branch on the remote:
364398
```
365399
$ git push <remote> :<branch> (since Git v1.5.0)
366-
or
367-
git push <remote> --delete <branch> (since Git v1.7.0)
400+
```
401+
OR
402+
```
403+
$ git push <remote> --delete <branch> (since Git v1.7.0)
368404
```
369405

370406
##### Publish your tags:
@@ -373,6 +409,16 @@ $ git push --tags
373409
```
374410
<hr>
375411

412+
#### Configure the merge tool globally to meld (editor)
413+
```bash
414+
$ git config --global merge.tool meld
415+
```
416+
417+
##### Use your configured merge tool to solve conflicts:
418+
```
419+
$ git mergetool
420+
```
421+
376422
## Merge & Rebase
377423

378424
##### Merge branch into your current HEAD:
@@ -397,11 +443,6 @@ $ git rebase --abort
397443
$ git rebase --continue
398444
```
399445

400-
##### Use your configured merge tool to solve conflicts:
401-
```
402-
$ git mergetool
403-
```
404-
405446
##### Use your editor to manually solve conflicts and (after resolving) mark file as resolved:
406447
```
407448
$ git add <resolved-file>
@@ -462,7 +503,7 @@ $ git reset --hard <commit>
462503

463504
##### Reset your HEAD pointer to a remote branch current state.
464505
```
465-
git reset --hard <remote/branch> e.g., upstream/master, origin/my-feature
506+
$ git reset --hard <remote/branch> e.g., upstream/master, origin/my-feature
466507
```
467508

468509
##### Reset your HEAD pointer to a previous commit and preserve all changes as unstaged changes:
@@ -484,6 +525,7 @@ $ git commit -m "remove xyz file"
484525
<hr>
485526

486527
## Git-Flow
528+
Improved [Git-flow](https://github.com/petervanderdoes/gitflow-avh)
487529

488530
### Index
489531
* [Setup](#setup)
@@ -500,7 +542,7 @@ $ git commit -m "remove xyz file"
500542

501543
##### OSX Homebrew:
502544
```
503-
$ brew install git-flow
545+
$ brew install git-flow-avh
504546
```
505547

506548
##### OSX Macports:
@@ -510,23 +552,28 @@ $ port install git-flow
510552

511553
##### Linux (Debian-based):
512554
```
513-
$ apt-get install git-flow
555+
$ sudo apt-get install git-flow
514556
```
515557

516558
##### Windows (Cygwin):
517559
###### You need wget and util-linux to install git-flow.
518-
```
519-
$ wget -q -O - --no-check-certificate https://github.com/nvie/gitflow/raw/develop/contrib/gitflow-installer.sh | bash
560+
```bash
561+
$ wget -q -O - --no-check-certificate https://raw.githubusercontent.com/petervanderdoes/gitflow/develop/contrib/gitflow-installer.sh install <state> | bash
520562
```
521563
<hr>
522564

523565
### Getting Started
524566
###### Git flow needs to be initialized in order to customize your project setup. Start using git-flow by initializing it inside an existing git repository:
525567
##### Initialize:
526568
###### You'll have to answer a few questions regarding the naming conventions for your branches. It's recommended to use the default values.
527-
```
569+
```shell
528570
git flow init
529571
```
572+
OR
573+
###### To use default
574+
```shell
575+
git flow init -d
576+
```
530577
<hr>
531578

532579
### Features
@@ -611,13 +658,13 @@ git flow hotfix finish VERSION
611658

612659
### Commands
613660
<p align="center">
614-
<img alt="Git" src="./Img/git-flow-commands.png" height="270" width="460">
661+
<img alt="Git" src="./Img/git-flow-commands.png" height="270" width="460">
615662
</p>
616663
<hr>
617664

618665
### Git flow schema
619666

620667
<p align="center">
621-
<img alt="Git" src="Img/git-flow-commands-without-flow.png">
668+
<img alt="Git" src="Img/git-flow-commands-without-flow.png">
622669
</p>
623670
<hr>

0 commit comments

Comments
 (0)