Get Started. It's Free
or sign up with your email address
Git by Mind Map: Git

1. Add

1.1. add a file(s) to index

1.1.1. $_git_add_<file_name>

1.2. add all new & changed files to index

1.2.1. $_git_add_.

2. Commit

2.1. commit staged changes

2.1.1. $_git_commit

2.2. commit from workspace to local repo

2.2.1. $_git_commit_-a

2.3. commit with a specified message

2.3.1. $_git_commit_-m_<message>

2.4. show diff when creating message

2.4.1. $_git_commit_-v

3. Diff/ls-files

3.1. show cached files

3.1.1. $_git_ls-files

3.2. diff working and index (What have you changed but not yet staged? )

3.2.1. $_git_diff

3.3. diff working and HEAD

3.3.1. $_git_diff_HEAD

3.4. diff index and HEAD

3.4.1. $_git_diff_--cached

3.5. diff index and HEAD (what have you staged that you are about to commit? )

3.5.1. $git__diff__ –statged

3.6. diff between two commit

3.6.1. git diff HEAD 46b186c

4. Log/Blame

4.1. show log

4.1.1. $_git_log

4.2. show blame info

4.2.1. $_git_blame_<file_name>

4.3. view certain number of commit

4.3.1. $_git__log__-p__-2

4.4. to decorate logs

4.4.1. git log --oneline –decorate

4.4.2. git log --oneline --decorate --graph --all

4.5. HEAD history

4.5.1. git reflog ( to see HEAD history)

4.5.2. git show HEAD@{5}

4.5.3. git show master@{yesterday}

4.6. see the previous commit

4.6.1. git show HEAD^

4.6.2. git show HEAD~2 (show second parent of head )

4.6.3. git show d921970^

4.6.4. git show HEAD~3^2, (show second parent of the third parent)

4.7. to get info about who and when file has been changed .

4.7.1. git blame README.md

5. Workflows

5.1. create a branch from an origin branch

5.1.1. git remote update

5.1.2. git checkout -b <branch> origin/<branch>

5.1.3. git pull origin <branch>

6. Stash

6.1. git stash pop

6.2. git stash apply

6.3. git stash list

6.4. git stash drop stash@{2}

6.5. git stash branch branchname stashid

7. git objects

7.1. #to show git objects

7.1.1. ls -F1

7.2. The description file is only used by the Git- Web program.

7.3. The config file contains your project specific configuration options,

7.4. the info directory keeps a global exclude file for ignored patterns that you don’t want to track in a .gitignore file.

7.5. The hooks directory contains your client- or server-side hook scripts. (triggered by operations such as committing and merging)

7.6. The objects directory stores all the content for your database,

7.7. the refs directory stores pointers into commit objects in that data (branches),

7.8. the HEAD file points to the branch you currently have checked out,

7.9. the index file is where Git stores your staging area information.

8. Squash

8.1. to combine commits together A conflict may occur

8.1.1. git rebase -i HEAD~3 (sqash 3 commit )

9. Branch

9.1. A branch in Git is simply a lightweight movable pointer to one of these commits

9.2. create a new local branch

9.2.1. $_git_branch_<branch_name>

9.3. show all local branches

9.3.1. $_git_branch

9.4. switch to a local branch

9.4.1. $_git_checkout_<branch_name>

9.5. create a new branch & checkout

9.5.1. $_git_checkout_-b_<branch_name>

9.6. delete a local branch after merging

9.6.1. $_git_branch_-d_<branch_name>

9.7. delete a local branch without merging

9.7.1. $_git_branch_-D_<branch_name>

9.8. rename a branch

9.8.1. $_git_branch_-m/-M_<old>_<new>

9.9. remove a remote branch

9.9.1. $_git_push_origin_:<banch>

9.10. see the last commit on each branch

9.10.1. git branch -v

9.11. list merged branches

9.11.1. git branch –merged

9.12. list unmerged branches

9.12.1. branch --no-merged

9.13. tracking remote branch

9.13.1. automatically create new branch and track the remote

9.13.1.1. git checkout --track origin/serverfix (local brach will have the same name as remote)

9.13.1.2. if you want different name you can run

9.13.1.2.1. git checkout -b [branch] [remotename]/[branch].

9.13.2. push to tracking branch

9.13.2.1. git push remote_name HEAD:remoteBranch

9.13.3. set upstream branch

9.13.3.1. git branch -u origin/serverfix

9.13.4. info about tracking branch

9.13.4.1. This will list out your local branches with more information including what each branch is tracking and if your local branch is ahead, behind or both.d

9.13.4.1.1. git branch -vv

9.13.5. untrack remote branch

9.13.5.1. git push origin --delete branchName( Basically all this does is remove the pointer from the server )

10. Merge

10.1. merge current branch w/ other branch

10.1.1. $_git_merge_<branch_name>

10.2. setup diffmerge

10.2.1. $_git_mergetool_-t_diffmerge

10.3. type of merge

10.3.1. fast-forward

10.3.2. three-way merge

10.4. after fetching remote (to show you the diff between your branch and remote .)

10.4.1. git log --no-merges issue54..origin/master

11. RM

11.1. stage a file to be removed from local repo and workspace

11.1.1. $_git_rm_<file_name>

12. Amend/Revert/Reset

12.1. amend

12.1.1. $_git_commit_--amend

12.2. revert

12.2.1. $_git_revert #idcommit

12.2.2. git revert -n #idcommit (will not create commit autoatically you need to commit explicitly )

12.3. reset

12.3.1. $_git_reset

12.3.2. # to unstage file

12.3.2.1. $_git__reset__HEAD__CONTRIBUTING.md

12.3.3. to discard changes in working directory .

12.3.3.1. $_git__checkout -- <file>.

12.3.4. return head back to last commit , but will not change anything in index or tree

12.3.4.1. git rest –soft HEAD~

12.3.5. reset will do is to update the Index with the contents of whatever snapshot HEAD now points to.

12.3.5.1. git rest –mixed HEAD~

12.3.6. reset all head and index and tree same

12.3.6.1. git rest –hard HEAD~

12.3.7. reset file

12.3.7.1. Git rest filename (same as --mixed)

12.3.8. Git rest Commit_number -- filename ( same as --mixed)

12.3.9. move the HEAD branch back to an older commit

12.3.9.1. git reset --soft HEAD~2

12.3.10. move the HEAD branch back to an specific commit

12.3.10.1. git reset --hard abe254d

13. Rebase

13.1. $_git_rebase__branch_name

13.2. rebase process

13.2.1. $git checkout experiment $ git rebase master $ git checkout master $ git merge experiment

13.3. revert last rebase

13.3.1. git reset --hard ORIG_HEAD

13.4. advance rebasing

13.4.1. $git rebase --onto master server client $git checkout master $ git merge client

13.5. rebase role

13.5.1. # you only rebase commits that have never been available publicly,

14. Rename File

14.1. $git_mv _file_old_name ____file_new_name

15. remote

15.1. add remote

15.1.1. git remote add <shortname> <url>:

15.2. show all remote

15.2.1. git remote -v

15.3. remove remote

15.3.1. git remote rm remote_name

15.4. rename remote

15.4.1. git remote rename old_name new_name

15.5. show specific remote

15.5.1. git remote show [remote-name]

15.6. push to remote branch

15.6.1. git push [remote-name] [branch-name].

15.7. fetch from remote

15.7.1. git fetch remotename

15.8. push to remote branch

15.8.1. git push -u origin featureB:featureBee

16. taging (to mark releases )

16.1. lightweight : A lightweight tag is very much like a branch that doesn’t change – it’s just a pointer to a specific commit.

16.1.1. # create lightweight tag

16.1.1.1. git tag v1.4-lw

16.2. annotated : Annotated tags, however, are stored as full objects in the Git database. They’re checksummed; contain the tagger name, email, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG).

16.2.1. create annotated tag

16.2.1.1. git tag -a v1.4 -m "my version 1.4

16.3. to show specific tag

16.3.1. git show v1.4

16.4. taging later to sepecific commit

16.4.1. git tag -a v1.2 9fceb02

16.5. push tag

16.5.1. push one tag

16.5.1.1. git push origin v1.5

16.5.2. push all tags

16.5.2.1. $ git push origin –tags

16.6. create new branch and mark it as release

16.6.1. Git checkout -b [branchname] [tagname]

16.7. git delete tag

16.7.1. git tag -d v1.1 git push origin -d v1.1

17. merge vs rebase

17.1. By merging you create a new commit with the result of the fusion of the target branch and source branch. With rebase you put the commit of the current branch on top of the source branch. Usage rules: * use rebase on your own branch before asking for a merge in order to have a clean history * use merge when you work with other people on the same branch

18. Note

18.1. You are asked to pull before you push, because someone pushed changes to the server, after your last pull, so our local copy and the current server copy are not in sync. Pulling will merge the remote copy with your local one, which brings them back into sync and allows you to push. The reason that you are not allowed to push straight away, is that this will need merging and mightlead to conflicts which need manual resolving. To avoid merging errors and conflicts, merging must always be done on the client side, never on the server.

19. cherry-pick (to pick commit and copy it to other branch)

19.1. git cherry-pick commitID

19.2. git cherry-pick #idcomit -e (edit commit) -x(hint that i sis cherry picked fromother brach )