Monday, June 15, 2015

Git & Git Server for linux



$git config –global core.quotepath false

git push origin --all -u
git push g --all -u

Internal Git Server in 5 Minutes

  1. Install linux server, Ubuntu Server 14.04 in my case.
  2. Install Git Server, GitLab in my case. follow the steps here.
  3. Config email setting following the steps here. Edit /etc/gitlab/gitlab.rb and run gitlab-ctl reconfigure. This step is necessary when add git users. Gmail SMTP In my case.
  4. Open Browser in Client, and log into server, add projects, add users.
    • for each project , add readme.md, and commit in browser
    • go to "Settings" of this project, "Protected branches" of settings, "Unprotect" the project.
    • Grant the users with right the project by going to "Project"-->"Settings" -->  "Members", and click "Add members" button. 
  5. Now, enjoy your personal internal Git Server.

Git Learning Resources:

  1. One of the best book <<Pro Git>> free to download downloaded at https://progit.org/ 
  2. ***** Learn Branching *****

Git dos and donts

The does
  1. Write useful, readable commit message
  2. use topic branches locally
  3. small, logical commits
  4. do choose a workflow
The don'ts
  1. Don't rebase public commits
  2. Don't delete unmerged remote branches
  3. Don't more than 1 project per repo.
  4. Don't create a very large repo.

Reference

 This document contains related resources to install Git Server.

Install Gitlab Server on Ubuntu:

  1. Follow the steps here to install gitlab 
  2. Config email setting following the steps here. Edit /etc/gitlab/gitlab.rb and run gitlab-ctl reconfigure

Git Client for Windows:

1: TortoiseGit on Windows:

  1. Refer to this youtube for usage.
  2. Easier to use, but not work in git way

2: SourceTree

  1. Use source tree for branching and merging, it's log and graph viewer is best by far. according to here
  2. Say hello to SourceTree for Windows 1.5
  3. does not provide explorer integration

3: Smart Git:Better Diff Viewer

Git Conflict Resolving:

  1. Very nice video on: Resolving merge conflicts in Git - Tutorial for Laura.
  2. Git Merge with BeyondCompare, refer to here

Misc:

  1. Permanently authenticating with Git repositories

Git Commands:

  1. git branch testing, git checkout testing
  2. gitk --all
  3. git log --oneline --graph --decorate --all
    1. git config --global alias.glog "git log --oneline --graph --decorate --all"
  4. git push -u secondary --all
  5. Gold Rebase Rule:
    1. Never rebase commits that you have pushed to a public repository

Fix Git

  1. git commit --amend: wrong commit
  2. git reset HEAD <file>
  3. git checkout -- <file> : give up change
  4. Tags:
    1. annotated
    2. lightweight
    3. git tag -a -m -lw
    4. git push [remote] --tags
  5. Cherry-Pick: git cherry-pick <commit name> <branch name>
  6. Bisect: binary search to find good commit or bad commit
  7. Stash: switch branches without committing work
  8. Revert: git revert <commit>
  9. Reset:            reset vs revert         12:00

Most Common Command

*** Git Main ***

Git: branch early, branch often

=== Git Merge ===
  • git branch newImage
  • git checkout newImage
  • git commit
  • git checkout master
  • git merge newImage
=== git rebase ===
  • git checkout bufFix
  • git rebase master
  • git checkout master
  • git rebase bufFix
=== HEAD & relative refs ===
  • git HEAD^
  • git HEAD^^
  • git HEAD~2
=== BRANCH Forcing ===
  • git branch -f master HEAD~3
=== Revert Changes ===
  • git reset : only works on local repo:    git reset HEAD^
  • git revert: git revert HEAD:    actually create a new snapshot
=== Moving Work Around ===
  • cherry-pick:    git cherry-pick <Commit1> <Commit2> <...>
  • interactive rebase:    git rebase -i HEAD~4 --aboveAll
  • Locally stacked commits   
=== Juggling Commits ===
  • git rebase -i HEAD~2    git commit --amend
  • git rebase -i HEAD~2    git rebase caption master
  • git rebase parentCommit childCommit

    *** Git Remote ***

     git clone,    fit fetch,   git pull
    • git pull
      • Equal
        • git cherry-pick o/master
        • git rebase o/master
        • git merge o/master
      • git pull == git fetch; git merge o/master
    === Git Fake ===
    • git fakeTeamwork
    • git fakeTeamwork foo 3
    • git pull --rebase
    • git pull; git push
    === Two ways to set remote tracking on a branch ===
    • git checkout -b foo o/master;     ==>  branch set to track o/master
      • if the foo branch is currently checked out, can leave off: git branch -u o/master
    • git branch -u o/master foo;          
    === Delete Remote Branch ===
    • git push origin <src>:<dest>
    • git fetch origin <src>:<dest>
      • git fetch origin foo: remote:foo branch ==> o/foo
    • --- to compare between local and remote/branch ---
    • git push origin :foo    ==> delete remote branch
    • git fetch origin :bar   ==> create local branch
    ===Introduction Sequence===
    [ ] Introduction
    [ ] Ramping Up
    [ ] Moving Work Around 
    [ ] A Mixed Bag
    [ ] Advanced Topics


    === rename tag ===
    Here is how I rename a tag old to new:

    git tag new old
    git tag -d old
    git push origin :refs/tags/old

    git push g --tags

    === Git Status Back ===
    • If you want to revert changes made to your working copy, do this:
      • git checkout .
    • If you want to revert changes made to the index (i.e., that you have added), do this:
      • git reset
      •  Warning this will reset all of your unpushed commits to master!
    • If you want to revert a change that you have committed, do this:
      • git revert ...
    • If you want to remove untracked files (e.g., new files, generated files):
      • git clean -f 
    • Or untracked directories:
      • git clean -d
    === Git Clone all ===

    === Check Ignored Files ===
    git status --ignored
    git clean -ndX
    for not ignore empty folder, add .gitkeep

    Git for large Projects with Many SubProjects


    Each module need to have separate version numbers. And we use 
    • Split out existing repository into subtree
    Setup a git difftool and mergetool.
    Easy Security - Microsoft Dynamic Nav Classic

    Mastering Git Subtree

    Adding a subtree - manual

    http://a/testtry/plugin.git
    http://a/testtry/main.git
    http://a/testtry/myown.git

    git remote add plugin ../remotes/plugin
    git fetch plugin
    git read-tree --prefix=vendor/plugins/demo -u plugin/master
    git commit -m "Added demo plugin subtree in vendor/plugins/demo"

    Grabbing/updating a repo that uses subtrees

    git push
    git clone remotes/main colleague
    cd colleague
    tree vendor


    Git Diff and Merge Tools

    1. install DiffMerge        ----commercial
    2. git config --global ... setting up several parameters
    3. git difftool
    4. git mergetool

    Git Power Routines - How To Solve Conflicts [5 8]

    1. git checkout --ours/--theirs actors.md

    Using vimdiff as your git diff tool..mp4

    1. Threesome.vim

    Git Workflow

    1. as SVN - Monly Master Branch
    2. feature Branch
    3. Gitflow

    Git Large Project

    1. Fetching Less Data: Git LFS 
    2. Shallow clones
    3. Narrow clones
    4. Android checkout 500 repositories when you download it.
    5. Handle multiple repositories:
      1. Repo: just a little Python wrapper
        1. ... with some extra features
        2. ... and an XML parser
      2. Git submodule
    6. Server
      1. Clone Bitmaps
      2. Clone Bundles

    Becoming a Git Master

    1. Git Liquid Prompt is awesome
    2. aliases are stored in .gitconfig
    3. git config --global rerere.enabled true
    4. git config --global rebase.autosquash true
    5. lock down your repo
    6. signing release tags is often all you need
    7. Handle project dependencies with git
    8. Git and project dependencies: http://bit.do/git-deps
      1. RepoBuild: written in C++ 
      2. Facebook Buck: Github, used to build android
      3. Pants Build : runs on linux and mac OSX, BuckBuild for android: 
      4. Other
        1. In quest of the ultimate build tool
    9. The power of git sub-tree
    10. Self Defined Class:
      1. GitPython.
      2. earwig/git-repo-updater

    Facebook Buck

    manually/main (master u=) $ git checkout -b split-plugin
    manually/main (split-plugin) $ git filter-branch \
      --subdirectory-filter lib/plugins/myown

        Labels: , ,

        1 Comments:

        At July 7, 2017 at 3:57 AM , Blogger Unknown said...

        Good blog post. Thanks for providing it with real time example code. Seems interesting to read, very useful post.
        Best Regards,
        DevOps Online Training in Hyderabad
        DevOps Training in Hyderabad
        DevOps Training
        Learn DevOps Online
        Devops Online Course

         

        Post a Comment

        Subscribe to Post Comments [Atom]

        << Home