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

1. RM

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

1.1.1. $_git_rm_<file_name>

2. Add

2.1. add a file(s) to index

2.1.1. $_git_add_<file_name>

2.2. add all new & changed files to index

2.2.1. $_git_add_.

3. Branch

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

3.2. create a new local branch

3.2.1. $_git_branch_<branch_name>

3.3. show all local branches

3.3.1. $_git_branch

3.4. switch to a local branch

3.4.1. $_git_checkout_<branch_name>

3.5. create a new branch & checkout

3.5.1. $_git_checkout_-b_<branch_name>

3.6. delete a local branch after merging

3.6.1. $_git_branch_-d_<branch_name>

3.7. delete a local branch without merging

3.7.1. $_git_branch_-D_<branch_name>

3.8. rename a branch

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

3.9. remove a remote branch

3.9.1. $_git_push_origin_:<banch>

3.10. see the last commit on each branch

3.10.1. git branch -v

3.11. list merged branches

3.11.1. git branch –merged

3.12. list unmerged branches

3.12.1. branch --no-merged

3.13. tracking remote branch

3.13.1. automatically create new branch and track the remote git checkout --track origin/serverfix (local brach will have the same name as remote) if you want different name you can run git checkout -b [branch] [remotename]/[branch].

3.13.2. push to tracking branch git push remote_name HEAD:remoteBranch

3.13.3. set upstream branch git branch -u origin/serverfix

3.13.4. info about tracking branch 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 git branch -vv

3.13.5. untrack remote branch git push origin --delete branchName( Basically all this does is remove the pointer from the server )

4. Commit

4.1. commit staged changes

4.1.1. $_git_commit

4.2. commit from workspace to local repo

4.2.1. $_git_commit_-a

4.3. commit with a specified message

4.3.1. $_git_commit_-m_<message>

4.4. show diff when creating message

4.4.1. $_git_commit_-v

5. Diff/ls-files

5.1. show cached files

5.1.1. $_git_ls-files

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

5.2.1. $_git_diff

5.3. diff working and HEAD

5.3.1. $_git_diff_HEAD

5.4. diff index and HEAD

5.4.1. $_git_diff_--cached

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

5.5.1. $git__diff__ –statged

5.6. diff between two commit

5.6.1. git diff HEAD 46b186c

6. Merge

6.1. merge current branch w/ other branch

6.1.1. $_git_merge_<branch_name>

6.2. setup diffmerge

6.2.1. $_git_mergetool_-t_diffmerge

6.3. type of merge

6.3.1. fast-forward

6.3.2. three-way merge

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

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

7. Log/Blame

7.1. show log

7.1.1. $_git_log

7.2. show blame info

7.2.1. $_git_blame_<file_name>

7.3. view certain number of commit

7.3.1. $_git__log__-p__-2

7.4. to decorate logs

7.4.1. git log --oneline –decorate

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

7.5. HEAD history

7.5.1. git reflog ( to see HEAD history)

7.5.2. git show [email protected]{5}

7.5.3. git show [email protected]{yesterday}

7.6. see the previous commit

7.6.1. git show HEAD^

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

7.6.3. git show d921970^

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

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

7.7.1. git blame

8. Amend/Revert/Reset

8.1. amend

8.1.1. $_git_commit_--amend

8.2. revert

8.2.1. $_git_revert #idcommit

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

8.3. reset

8.3.1. $_git_reset

8.3.2. # to unstage file $

8.3.3. to discard changes in working directory . $_git__checkout -- <file>.

8.3.4. return head back to last commit , but will not change anything in index or tree git rest –soft HEAD~

8.3.5. reset will do is to update the Index with the contents of whatever snapshot HEAD now points to. git rest –mixed HEAD~

8.3.6. reset all head and index and tree same git rest –hard HEAD~

8.3.7. reset file Git rest filename (same as --mixed)

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

8.3.9. move the HEAD branch back to an older commit git reset --soft HEAD~2

8.3.10. move the HEAD branch back to an specific commit git reset --hard abe254d

9. Stash

9.1. git stash pop

9.2. git stash apply

9.3. git stash list

9.4. git stash drop [email protected]{2}

9.5. git stash branch branchname stashid

10. Rebase

10.1. $_git_rebase__branch_name

10.2. rebase process

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

10.3. revert last rebase

10.3.1. git reset --hard ORIG_HEAD

10.4. advance rebasing

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

10.5. rebase role

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

11. Workflows

11.1. create a branch from an origin branch

11.1.1. git remote update

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

11.1.3. git pull origin <branch>

12. Rename File

12.1. $git_mv _file_old_name ____file_new_name

13. remote

13.1. add remote

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

13.2. show all remote

13.2.1. git remote -v

13.3. remove remote

13.3.1. git remote rm remote_name

13.4. rename remote

13.4.1. git remote rename old_name new_name

13.5. show specific remote

13.5.1. git remote show [remote-name]

13.6. push to remote branch

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

13.7. fetch from remote

13.7.1. git fetch remotename

13.8. push to remote branch

13.8.1. git push -u origin featureB:featureBee

14. taging (to mark releases )

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

14.1.1. # create lightweight tag git tag v1.4-lw

14.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).

14.2.1. create annotated tag git tag -a v1.4 -m "my version 1.4

14.3. to show specific tag

14.3.1. git show v1.4

14.4. taging later to sepecific commit

14.4.1. git tag -a v1.2 9fceb02

14.5. push tag

14.5.1. push one tag git push origin v1.5

14.5.2. push all tags $ git push origin –tags

14.6. create new branch and mark it as release

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

14.7. git delete tag

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

15. merge vs rebase

15.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

16. git objects

16.1. #to show git objects

16.1.1. ls -F1

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

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

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

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

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

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

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

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

17. Note

17.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.

18. Squash

18.1. to combine commits together A conflict may occur

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

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 )