Intro to Git - raisercostin/software-wiki GitHub Wiki

Main commands

For install go to Install section.

Anti-Patterns

Feature Branches vs Trunk Branch

Patterns

Configuring

Is best to have the following configuration

git config --global credential.helper wincred

# Don't autocorrect EndOfLines between windows/linux/osx
git config --global core.autocrlf false
git config --global pull.rebase true

# Use iso date format YYYY-MM-DD HH:mm:ss +Z: like in 2006-07-03 17:18:43 +0200
git config --global log.date iso8601

git config --global credential.helper="C:/Users/CostinGrigore/scoop/apps/git/current/mingw64/bin/git-credential-manager.exe"
git config --global user.name "Costin Grigore"
git config --global user.email "[email protected]"

echo windows longpaths
git config --global core.longpaths true
--


<!--EndFragment-->
</body>
</html>

Credentials

git config --global user.email [email protected]
git config --global user.name yourUsername

Older


# Configure git to use project wide, shared, local hooks like pre-commit . Add to `.githooks\` folder any hooks from `.git\hooks\*.sample` and remove sample
#git config core.hooksPath .githooks\

Filtering Branch

Rebasing

Working with rebase

git checkout -b dev/costin1
git checkout -b dev/costin2
tortoisegitproc /command:revisiongraph
git checkout -b dev/costin3
git checkout -b dev/costin3 master
git checkout -b dev/costin4 master
 
git checkout master
git checkout master --force
git checkout -b dev/costin4
git commit -am "fix"
git push --force
git push --set-upstream origin dev/costin4
git push --set-upstream origin dev/costin3
git fetch -v --progress --prune "origin"

Replace master branch with another branch

Authorization Patterns

In git a user can have read or read/write access. Usually there are no permission control over parts of the folders from git. There is a form of permission control on branches. The patterns are:

  1. Read Only
  2. Read/Write
  3. Pull Request

Read Only

By default in Github/Gitlab the owner is the only one that has write rights. All other users have read rights so they can clone and fork. Forking in github will give you access to a writable entire repository.

Read/Write

Your own projects or projects where you where added as a collaborator.

Pull Requests

Pull requests are a way that allows a forker to contribute back to the original repository. After you make some changes in a place you are allowed to write (repository or branch) you may ask for an accept of a merge: that is the pull request. The owner is informed and can make a decision to accept or reject your pull request. The name clarifies this: you cannot make a push so you ask the owner to pull from your branch/repository. See more about it:

Usage

Flow Practices - http://nvie.com/posts/a-successful-git-branching-model/

  • cheatsheet file lifecycle
  • patterns
    • authorization patterns
      • with pull-requests
      • as collaborators
  • some useful commands
    • store password in shell session
      • linux: git config --global credential.helper store
      • windows: git config --global credential.helper wincred
    • fetching everything including deletion on remote repository: git fetch --prune
    • pushing stuff (including deleting from remote) - https://stackoverflow.com/questions/5480258/how-to-delete-a-git-remote-tag. By omitting the source ref (the part before the colon), you push 'nothing' to the destination, deleting the ref on the remote end. git push where-to-push source-ref:destination-ref
    • delete branch (see https://makandracards.com/makandra/621-git-delete-a-branch-local-or-remote)
      • from local repository git branch -d the-local-branch
      • from remote repository git push origin :the-remote-branch
    • add remote repo git remote add new-repo-name http://server.org/.../new-remote-repo.git
    • configure local repo as remote
      • git config --unset core.bare
      • git config receive.denyCurrentBranch updateInstead
    • merging but ignoring any proposed change: git merge origin/branch-to-ignore -s ours
  • others

    git add *App.java
    git add *AppTest.java
    git add -A
    git add .gitignore 
    git add App.java
    git add README.md 
    git branch -a
    git checkout -b user/costin
    git checkout -b user/costin-madalin
    git checkout -b user/costin-ship3
    git checkout -b user/costin-ship3b
    git checkout master
    git checkout user-Andrei
    git checkout user-Gabi
    git checkout user-Gabriel
    git checkout user-Lucian
    git checkout user-Madalin
    git checkout user-Stefan
    git checkout user-Victor
    git checkout user-Victor\
    git checkout user/costin-ship3
    git clone https://github.com/raisercostin/dcsi.git
    git clone https://github.com/raisercostin/dcsi.git ship2
    git clone https://github.com/raisercostin/dcsi.git ship3
    git commit
    git commit -am "add backlog"
    git commit -am "restructure/refactor"
    git commit -m "read users"
    git commit -m "refactored"
    git config --global credential.helper wincred
    git config --global user.email "[email protected]"
    git config --global user.name "raisercostin"
    git fetch
    git merge user/costin
    git merge user/costin-ship3
    git merge user/costin-ship3b
    git pull
    git push
    git push --set-upstream origin user/costin-madalin
    git push --set-upstream origin user/costin-ship3
    git push --set-upstream origin user/costin-ship3b
    git push --set-upstream origin user/costin-ship3c
    git push --set-upstream origin user/costin
    git status
    mvn compile
    mvn eclipse:eclipse
    mvn eclipse:eclipse -DdownloadSources
    mvn test
    git config --global core.autocrlf false
    git config --global log.date iso8601
    
  • github badges - https://shields.io/

Advanced

Practices

Operations

  1. List all tags that point to a commit

    git tag --points-at f96e7cadce8eda56b037b10a31fbd3815eaa8b3f|xargs git tag -d

  2. Delete a set of tags from console xargs git tag -d <&1

  3. Get history for a file or files
    See

                         git read-tree --empty
                         git reset $GIT_COMMIT -- $your $files $here
                 ' \
         -- --all -- $your $files $here
    
  4. print last commit number: git log --oneline | wc -l Ref: https://stackoverflow.com/a/21607276/9337419

  5. print last commit short SHA: git rev-parse --short HEAD Ref: https://stackoverflow.com/a/5694416/9337419

  6. print last commit date and time: git log -1 --date=format:%Y_%m_%d-%H_%M_%S --pretty=format:%cd Ref: here and here

Install

OSX

brew install git

QA

  1. What kind of commits exists?

    Git-Changes

⚠️ **GitHub.com Fallback** ⚠️