Table of Contents
- 1. SHA1 (default)
- 2. CLA and DCO, signoff and gpg-sign
- 3. GitHub actions - CI/CD platform
- 4. GitHub special files
- 5. Github search
- 6. install git
- 7. Global settings: Author identity unknown, proxy
- 8. revisions
- 9. Definitions
- 10. commands
- 11. branches
- 12. remote branches, upstream braches and symrefs
- 13. User/Password locally for repository (save password in repository)
- 14. log
- 15. merge
- 16. markdown
- 17. pages
- 18. decentralized share
- 19. branch metodology (rus)
- 20. commit metodology
- 21. image upload
- 22. EXAPLES
- 23. USE CASE
- 23.1. see changes
- 23.2. branches
- 23.3. explore unknown repo
- 23.4. pull forced
- 23.5. delete all hisotry / remove all commits
- 23.6. delete commits after
- 23.7. check if working tree has local changes
- 23.8. seach
- 23.9. merge changes in big priject - instruction
- 23.10. restore file to HEAD
- 23.11. get all authors
- 23.12. git move between commits
- 24. join commits together, merge commits, squash commits, Squash commits into one
- 25. humor
- 26. Troubleshooting
- 27. status badge
- 28. python bots
- 29. https://jonas.github.io/tig/
;-- mode: Org; fill-column: 100;-- git clone ssh://git@github.com/<user>/<repository_name>.git https://packages.gentoo.org/categories/dev-vcs
1. SHA1 (default)
it defaults to using seven characters:
git log --oneline or --abbrev-commit
At its core, the Git version control system is a content addressable filesystem. It uses the SHA-1 hash function to name content.
- these simple names are called “references” or “refs”; (.git/refs directory.)
2. CLA and DCO, signoff and gpg-sign
CLA (Contributor License Agreement)
Copyright transfer/assignment agreement - an agreement that transfers the copyright for a work from the copyright owner to another party. ex: a video game developer who wants to pay an artist(painter) to draw a boss to include in a game
DCO (Developer Certificate of Origin) - way for contributors to certify that they wrote or otherwise have the right to submit the code they are contributing to the project.
- aggree to "the contributor is allowed to make the contribution and that the project has the right to distribute it under its license"
- introduced in 2004[1] by the Linux Foundation
- Sign-off is a requirement for getting patches into the Linux kernel and a few other projects, but most projects don't actually use it.
- Sign-off is a line at the end of the commit message which certifies who is the author of the
commit. Its main purpose is to improve tracking of who did what, especially with patches.
- Signed-off-by: Humpty Dumpty <humpty.dumpty@example.com>
-s::–signoff:: - add line to commit message to signal that you created this commit, have permission to submit it, and you adhere to the project licensing.
-S –gpg-sign - adds a gpg signature to the commit which requires one to have gpg installed and a private key. GitHub will mark commits that you sign with the verified label. If you sign your tags, they will also be marked as verified.
3. GitHub actions - CI/CD platform
3.1. theory
It uses main branch only.
When you enable GitHub Actions, GitHub installs a GitHub App on your repository.
3.2. features
- automatically add the appropriate labels whenever someone creates a new issue in your repository
- provides Linux, Windows, and macOS virtual machines to run your workflows, or you can host your own self-hosted runners in your own data center or cloud infrastructure
3.3. terms
- event
- in repository
- workflow
- defined by a YAML file in .github/workflows/. Triggered by: event, manually, at schedule.
- jobs
- part of workflow, set of steps. run sequential or parallel(default) in one workflow. May depend on other job.
- runner
- Each job will run inside its own virtual machine or container.
- steps
- of job. run a script or run an action. executed in order.
- default environment variables
- that GitHub sets automatically
- custom variables
- user definde
- activity type
- specify which activity trigger event.
3.4. workflow file
workflow is divided into jobs, and each job performs a set of steps
specifies what commands or scripts to run, the default settings, the environment for the commands, etc.
- name (optional)
- name of your workflow, if not specified GitHub sets it to the workflow file path.
- run-name (optional)
- name for workflow runs, if omitted then for a workflow triggered by a
push or pull_request event, it is set as the commit message.
- ex. Deploy to ${{ inputs.deploy_target }} by @${{ github.actor }}
- on
- events if just list. ex. [push, fork]
- jobs
- check-bats-version
- example job name
- ubuntu-latest
- ex. ubuntu-latest.
3.5. examples of workflow files
3.5.1. checks out the pushed code, installs the bats testing framework, and runs a basic command to output the bats version
name: learn-github-actions run-name: ${{ github.actor }} is learning GitHub Actions on: [push] jobs: check-bats-version: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '14' - run: npm install -g bats - run: bats -v
{True: ['push'], 'jobs': {'check-bats-version': {'runs-on': 'ubuntu-latest', 'steps': [{'uses': 'actions/checkout@v3'}, {'uses': 'actions/setup-node@v3', 'with': {'node-version': '14'}}, {'run': 'npm ' 'install ' '-g ' 'bats'}, {'run': 'bats ' '-v'}]}}, 'name': 'learn-github-actions', 'run-name': '${{ github.actor }} is ' 'learning GitHub Actions'}
3.6. variables
custom variable
- env key in workflow file.
- env:\n\t DAY_OF_WEEK: Monday
- jobs: env:\n\t DAY_OF_WEEK: Monday
- jobs: steps: env:\n\t DAY_OF_WEEK: Monday
- define it at the organization, repository, or environment level
3.7. events that trigger workflows
on: {release: {types: [published]}} on: {schedule: [cron: '30 5,17 * * *']} "on": [push]
Every event has "activity type" which describe it further.
events https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
3.7.1. frequent events:
- push - triggered when a commit is pushed to the repository
- pull_request - triggered when a pull request is opened or updated
- workflow_dispatch - triggered manually by a user or API call
- release - triggered when a new release is created. GITHUB_SHA, GITHUB_REF (refs/tags/<tag_name>)
other:
- schedule - triggered on a specified schedule (e.g. daily, weekly)
- repository_dispatch - triggered by a custom event from an external system or API
- page_build - triggered when a GitHub Pages site is built
- issues - triggered when an issue is opened, edited, or labeled
3.7.2. ex
on: push: # Sequence of patterns matched against refs/heads branches: - main - 'mona/octocat' - 'releases/**' pull_request:
3.8. secrets and variables
Repository -> settings -> Secrets and variables -> Actions
referencing secrets: ${{ secrets.GITHUB_TOKEN }}
3.8.1. GITHUB_TOKEN
GITHUB_TOKEN - created before each job begins, expires when a job finishes. Usage: passing the token as an input to an action, or using it to make an authenticated GitHub API request. the default permissions are restrictive.
- permissions:
permissions: actions: read|write|none checks: read|write|none contents: read|write|none deployments: read|write|none id-token: read|write|none issues: read|write|none discussions: read|write|none packages: read|write|none pages: read|write|none pull-requests: read|write|none repository-projects: read|write|none security-events: read|write|none statuses: read|write|none permissions: read-all|write-all permissions: {} # disable permissions
- usage example:
name: Create issue on commit on: [ push ] jobs: create_issue: runs-on: ubuntu-latest permissions: issues: write steps: - name: Create issue using REST API run: | curl --request POST \ --url https://api.github.com/repos/${{ github.repository }}/issues \ --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ --header 'content-type: application/json' \ --data '{ "title": "Automated issue for commit: ${{ github.sha }}", "body": "This issue was automatically created by the GitHub Action workflow **${{ github.workflow }}**. \n\n The commit hash was: _${{ github.sha }}_." }' \ --fail
3.9. jobs
jobs: check-links: # job ID name: My first job # which is displayed in the GitHub UI. (optional) runs-on: ubuntu-latest steps: - run: npm install -g bats - name: do something important run:
job runners: https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job
3.10. actions
- setup-python https://github.com/actions/setup-python
- checkout https://github.com/actions/checkout
- stale https://github.com/actions/stale
- setup-java https://github.com/actions/setup-java
- setup-go https://github.com/actions/setup-go
- pypa/gh-action-pypi-publish https://github.com/pypa/gh-action-pypi-publish
3.10.1. checkout
to GITHUB_WORKSPACE
Only a single last commit is fetched by default.
options:
- repository
- Default: ${{ github.repository }}
- ref
- uses the default branch
3.10.2. ex
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }}
3.11. variables
https://docs.github.com/en/actions/learn-github-actions/variables
reffered as $GITHUB_WORKSPACE:
- GITHUB_WORKSPACE
- The default working directory on the runner for steps, and the default location of your repository when using the checkout action.
- RUNNER_OS
3.11.1. secrets
- Names must not start with the GITHUB_ prefix.
- Names must not start with a number.
- Names are case insensitive.
${{ secrets.GITHUB_TOKEN }} - special
with: # Set the secret as an input super_secret: ${{ secrets.SuperSecret }} env: # Or as an environment variable super_secret: ${{ secrets.SuperSecret }}
3.12. runs-on
Each job runs in a fresh instance of the virtual environment specified by runs-on.
3.13. passing data between …
- actions/upload-artifact and actions/download-artifact
- volumes - to share data between services or other steps in a job.
- outputs - maximum of 1 MB. The total of all outputs in a workflow run can be a maximum of 50 MB.
3.14. release
- create new release
- https://github.com/elgohr/Github-Release-Action
- gh release create –title "\({INPUT_TITLE}" --generate-notes "\)(date +%Y%m%d%H%M%S)"
- add asset to existent release
- gh release upload ${{ github.ref_name }} ./dist/*{.exe,.exe.sha512.txt}
3.15. links
4. GitHub special files
4.1. docs/CONTRIBUTING.md
README.md:
[Contribution guidelines for this project](docs/CONTRIBUTING.md)
or in your root directory
think of it as a anchor for your project, around which you will build community and keep things tidy. provides potential project contributors with a short guide to how they can help with your project or study group
- Project contributors - users of the file who want to know items they're welcome to tackle, and tact they need in navigating the project/respecting those involved with the project
- Project consumers - users who want to build off the project to create their own project
4.2. .git-blame-ignore-revs
Contains commit hashes with big refactorings that you don't want to be shown in history of review.
4.3. .github/CODEOWNERS
notifications for pull requests, for feedback
path name of owner
4.4. .github/SECURITY.md
Security Policy
how to report
4.5. .gitignore
- .gitignore - will be added to repository
- .git/info/exclude - without adding .gitignore to repo
- ~/.gitignore_global - global for all repositories
remove ignored files from current repository:
- git rm -r –cached .
- git add .
- git commit -am 'Drop files from .gitignore'
4.6. TODO .gitlab-ci.yml
obsolate?
5. Github search
file
- filename:my_filename.txt or "path:**/your-file-name" or "path:your-file-name"
stars
- cats stars:>1000 matches repositories with the word "cats" that have more than 1000 stars.
filesize
- cats size:<10000 matches code with the word "cats" in files that are smaller than 10 KB.
dates
- cats created:>2016-04-29 matches issues with the word "cats" that were created after April 29, 2016.
label
- build label:"bug fix"
issues
- is:issue assignee:@me matches issues assigned to the person viewing the results
exclude:
- -org:github - not in repositories in the GitHub organization.
- -language:javascript
- hello NOT world matches repositories that have the word "hello" but not the word "world."
6. install git
- git config –global user.email "<larry@gentoo.org>"
- git config –global user.name "Larry the cow"
- git config –global core.editor emacs
- git init
- git add .
- git commit
7. Global settings: Author identity unknown, proxy
7.1. global config files
.git/config [user] section:
- git config user.email ""
- git config user.name "(none)"
~/.gitconfig git config –global –list git config –list - repository config
7.2. proxy
git supported protocols:
- http: git clone http://domain.com/dir/repository.git
- https: git clone https://domain.com/dir/repository.git
- git: git clone git://domain.com/dir/repository.git
- git over ssh: git clone git+ssh://domain.com/dir/repository.git
set proxy:
git config --global http.proxy 'socks5://127.0.0.1:1081' # for http protocol http://proxyuser:proxypwd@proxy.server.com:8080 git config --global ssh.gitproxy /path/to/bin/git-proxy.sh # for git protocol
/path/to/bin/git-proxy.sh where $1 and $2 is remote host and port:
nc -x 127.0.0.1:1081 $1 $2
git config –list # should look like this:
http.proxy=socks5://127.0.0.1:1081 core.gitproxy=/home/user/git-proxy.sh
core.gitproxy is not working, idk why.
7.3. ssh
Host github.com ServerAliveInterval 55 ForwardAgent yes CheckHostIP no ProxyCommand nc -xlocalhost:9050 -X5 %h %p
8. revisions
man gitrevisions
- <rev> - revision - commit or blobs ("files") or trees ("directories of files") whis is conteined in commit.
- <sha1> - extended SHA-1 syntax
- <describeOutput> Output from git describe; i.e. a closest tag, optionally followed by a dash and a number of commits,
- <refname>, e.g. master, heads/master, refs/heads/master
- [<refname>]@{<date>}
- <refname>@{<n>}, e.g. master@{1}
- n-th prior value of that ref.
- @{<n>}, e.g. @{1}
- <rev>^[<n>], e.g. HEAD^, v1.5.1^0 - n-th parent
- A suffix ^ to a revision parameter means the first parent up to tree of that commit object. <rev>^ is equivalent to <rev>^1
- A^<n> - mean <n> parent where a commit has more than one parent
- A^0 = A
- <rev>~[<n>], e.g. HEAD~, master~3
- A~2 - seond parent up to branch = A^^
- r1 .. r2 - revision range
- r1..r3 = r2 r3 = r3 ^r1
- r1^..r3 = r1 r2 r3
- r1 … r2 - all parents of both
9. Definitions
http://www.vogella.com/tutorials/Git/article.html https://www.tutorialspoint.com/git/git_basic_concepts.htm
Version Control System (VCS) [ˈvɜːʃən] is a software that helps software developers to work together and maintain a complete history of their work.
Git - distributed version control system.
Repository - software storage local or remote. contains the history and branches.
- Bare repository - git init –bare For sharing in collaborating. repository without working tree. Not allow tocreate new versions. (commit i guess)
- Local Repository - .git folder at local machine
Working tree - folder for the repository (tracked and untracked). staging area (Index) - git add list of files with sha1 of content - tracked files. Stagging or cached - changes that will be included in next commit. (after git add)
Checkout - Updates files(remove changes) in the working tree to match the version in the index or the specified branch.
Commit 1)commit the staged changes into Git repository 2)commit object - uniquely identifies(SHA-1 hash) a revision(state) of the repository(content). Has pointer to parent commit.
If commit has miltiple parent commits - was created by merging.
- First parent commit is the branch you were on when you merged A^, A^2 - second parent
Version graph formed by all commits in the repository
HEAD - symbolic reference. If you switch branches, the HEAD pointer points to the branch pointer which in turn points to a commit. If you checkout a specific commit, the HEAD points to this commit directly.
.gitignore the root directory of your project, the ignore settings will be applied to all sub-directories automatically.
Detached HEAD mode - If you checkout a commit or a tag
ref - symbolic references (symrefs)
Upstream branch - branch tracked on remote repository by your local remote "tracking" branches.
- Local remote "tracking" branches - local branches that has remote associatied in .git/config
- remote tracking branches - branches on remote version of local repository
- "remotes" - remote repository, configured in git remote. ex. origin
9.1. Pull
from remote repository instance to local one.
9.2. Push
from local to remote
9.3. Branch
https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches Branch - are local for the repository. A branch is a named pointer to a commit.
Remote-tracking branches - there are remote branches. Looks like origin/master. not stored localy. but may be checkout.
local branches - looks like master. they are stored in local repository.
To have an upstream branch(tracking branches) - –track This configuration will tell git to show the relationship between the two branches in git status and git branch -v. If you clone a Git repository, your local master branch is created as a tracking branch for the master branch of the origin repository (short:_origin/master_) by Git. Always local.
upstream branch - the branch which tracking branch tracks. Always Remote-tracking branches.
Default branch - named _master
9.4. TAG
Tag - points to a commit.
Lightweight tag - without properties, annotated tag - with additional info
Release tags - common applying of tag.
9.5. .git/config, remote
Fetchurl, Pushurl - the location of the repository
Remote - remote repository pointer with properties e.g. URL, branches to fetch or branches to push.
Origin - default name for remote. after clone
9.6. Submodule
Git-submodule - via a .gitmodules file located at the root of the parent repository. They’re too intrusive, requiring submodules to be initialised and updated. And switching between branches, which is where Git really shines, suddenly becomes painful because submodules don’t do what you expect.
git merge git rebase - like merge but add current branch commits at the top of rebase branch
git fetch - move local Remote-tracking branche to what at remote repository. it may add commits not existing in another local branches.
By default you can only push to bare repositories.
release tags are labeled based on the [major].[minor].[patch] naming scheme, for example "1.0.0". Several projects also use the "v" prefix. the minor version is incremented if new, backwards compatible functionality is introduced to the public API and the major version is incremented if any backwards incompatible changes are introduced to the public API.
To get submodules for project:
- git checkout –recurse-submodules
- git submodule update –depth 1 –init –checkout –recursive
9.7. cherry-pick
act of picking a commit from a branch and applying it to another.
most of this can be made with git merge
10. commands
- git init/clone
- git stash - save working directory state and allow list saves
- git rm [file] - remove files from the index and maybe(–cached) working tree
- git mv - move file, directory symlink, index updated, but changes must be commited
- git add - update the Index = add files and update check-sum.
- git clean - Remove untracked files from the working tree
- git log
- git reflog - local actions history - git reset HEAD@{index}
- git show
- git diff
- git diff HEAD - between Staging Area and HEAD commit (git diff "s" HEAD - "s"=a, HEAD=b)
- git diff –staged/cached HEAD - between Stagging and HEAD
- git branch
- git switch - switch branches
- git checkout -switch
- git commit
- –amend - replace last commit of current branch
- git merge - combines branches
- git merge –abort
- git revert - revert one commit and record new one
- git reset - sets HEAD to comment (and reset index and/or working tree)
- –mixed - reset index but not working tree
- –soft - do not touch index and working tree
- –hard - index and working, changes are lost
- –merge - reset index and update files in working if they different in past commit
- –keep - reset index and update files in working if they dont have local changes
- git reset file - reset file to HEAD
- git remote - manage remote repositories
- git fetch - harmless download changes
- git pull - download changes and change working tree
11. branches
switch
- git switch branch name
create
- git branch name # create a branch from the current branch, do not switch to it
- git branch <name> <hash> - <hash> is optional to which the branch pointer original points
- git checkout [[-b|-B|–orphan] <new_branch>] [<start_point>] # git branch -f <branch> [<start-point>] ; git checkout <branch>
- git checkout -b name # new branch and start at the start poing
- -B <new-branch> # <new-branch> is created if it doesn’t exist otherwise, it is reset
- git switch -c new-branch # git branch <new-branch> ; git switch <new-branch>
- git switch -c dev –track master # If the starting point is a local branch, you can force the tracking
delete
- git branch -d testing - delete local branch
- git branch -d -r origin/dev origin/stage origin/prod # delete remote-tracking branches.
- git push [remote] –delete [branch] - delete branch in a remote repository
list
- get branch -r # remote branches (red)
- git branch # show local branches (green with * is current)
- git branch -a - lists all branches including the remote branches
- git branch -r - lists branches in the remote repositories
- git branch -v - info of tracking branches
- git remote show origin - show all remote and tracking branches for origin
- git branch -vv - to see local tracking branches.
- git branch –merged/–no-merged [commit] # Only list branches whose tips are reachable
other
- git branch -D name # delete a local copy of a branch.
- git checkout -b develop -
- –orphan - no parents, totally disconnected. no commits before first
- # tracking branches
- git checkout -b newbranch origin/newbranch - setup a tracking branch called newbrach which tracks origin/newbranch
- git branch [new_branch] origin/master
- git checkout –track origin/serverfix - create local serverfix branch tracking remote one if remote exist.
- git checkout serverfix - the same
- git branch –unset-upstream # Remove a current tracking relationship
- git push -u origin feature # Link a branch to an upstream branch
- git branch –set-upstream-to # set remote tracking branch
11.1. theory
upstream tracking branch: master ⇒ origin/master
by default both “git merge” and “git rebase” will use the upstream tracking branch
when you checkout a new branch and you are using a remote branch as the starting point, the upstream tracking branch will be setup automatically.
12. remote branches, upstream braches and symrefs
- git remote - show "remotes" whose branches you track
- git branch -r - remote tracking branches (branches on remote version of local repository)
- * - currently viewing
- origin/HEAD -> origin/master - default branch and current commit of origin. may be changed with: git remote set-head origin <remote> <branch>
- origin/master - remote branch
- cat .git/config
- remote = origin - remote associated with branch (upstream configuration)
- merge = refs/heads/master - branch and HEAD on remote
12.1. kinds of symrefs
git symbolic-ref
- .git/HEAD, pointing at somewhere under refs/heads/ hierarchy;
- .git/refs/remotes/{some remote name}/HEAD, pointing at somewhere under refs/remotes/{the same remote name}/ hierarchy.
13. User/Password locally for repository (save password in repository)
- git config credential.helper store
- after next push credentials will be saved
14. log
git log
- –oneline -
- –graph
- –decorate[=short|full|auto|no] lenght of ref name - default short
git log HEAD~4..HEAD git log HEAD~4 - the same git log testing..master - list all commints in master but not in testing git log master…testing - commits reached by master or testing but not both
git log HEAD – git log -1 – HEAD - one last commit for HEAD file git log HEAD^ - one parent commit for HEAD
15. merge
fast-forward is merge operation when Git moves the current branch HEAD pointer to the target local branch HEAD pointer, without having extra commits.
merge branch
- git checkout master
- git merge development
if CONFLICT
- undo
- git merge –abort
- git merge –continue
- resolve
- open conflicted file to see
- remove <<<<<,
==
amd >>> lines to resolve conflict - git add ./path/file ( if new)
- git commt -m "Merge development fixed conflict"
16. markdown
GitHub Flavored Markdown with a few unique writing features (один из диалектов Markdown)
- file.md
16.1. headers
# A first-level heading ## A second-level heading ### A third-level heading
16.2. code
one word: `nano`. frase: ``Use `code` in your Markdown file.`` Blocks: ```python import os ```
16.3. all
## The second largest heading ###### The smallest heading **This is bold text** > Text that is a quote Use `git status` to list all new or modified files that haven't yet been committed. ``` git status git add git commit ``` : This site was built using [GitHub Pages](https://pages.github.com/). : [Contribution guidelines for this project](docs/CONTRIBUTING.md) : ![This is an image](https://myoctocat.com/assets/images/base-octocat.svg) : [![name](link to image on GH)](link to your URL) : <https://www.markdownguide.org> : <fake@example.com> : I love supporting the **[EFF](https://eff.org)**. List: - George Washington - John Adams - Thomas Jefferson To order your list: 1. James Madison 2. James Monroe 3. John Quincy Adams Nested Lists 1. First list item - First nested list item - Second nested list item <!-- This content will not appear in the rendered Markdown --> | First Header | Second Header | | ------------- | ------------- | | Content Cell | Content Cell | | Content Cell | Content Cell | | Command | Description | | --- | --- | | `git status` | List all *new or modified* files | | `git diff` | Show file differences that **haven't been** staged | Align: | Left-aligned | Center-aligned | Right-aligned | | :--- | :---: | ---: | | git status | git status | git status | | git diff | git diff | git diff |
16.4. links
17. pages
repo -> Settings ->pages
Preview:
HTML:
- touch .nojekyll
- /_site/index.html
- Settings -> pages https://anoncheg1.github.io/awesome-chinese/
pages
- GitHub Pages supports two Markdown processors: kramdown and GitHub's own Markdown processor, which is used to render GitHub Flavored Markdown (GFM)
18. decentralized share
/etc/conf.d/git-daemon
- GIT_USER="t"
- GIT_GROUP="t"
- GITDAEMON_OPTS="–syslog –export-all –enable=receive-pack –base-path=/home/t/share"
- If desired to accept git push and allow access all direct, it needs two options –enable=receive-pack and –export-all in GITDAEMON_OPTS
or use sshfs to directly access folder
19. branch metodology (rus)
- Central Workflow - one master branch
- Forking Workflow - 1) original or main branch 2) fork branch owned by another contributor which going to suggest merges to main
- Developer Branch Workflow - one main and every developer has one or more own branches. finally forks will be merged to main.
- Github Flow - (good for agile teams) - extension to provide high-level repository operations for Vincent Driessen's branching model
- main branch - code works and ready to deploy at any time
- all brancches (features) - checked by leader of the team + one more specialist then merged to main
- Feature Branch Workflow -
- main - stable
- dev -
- features branches - created from dev. finally merged to dev
- Git Flow - big projects
- main branch or production - stable
- develop - may be not stable
- release1-9 branches - stabilization work take place here and merged to develop and master
- hotfix1-9 branches - for fast solving of critical problem of production branch. merged to develop and master.
- Issue Branch Workflow - like a "Feature Branch Workflow" but with for issues
19.1. link
20. commit metodology
consist of
- action
- subject
- comments
vocabulary:
- init — инициализация;
- add — добавление;
- delete — удаление;
- update — изменение;
- fix — исправление;
- refactor — рефакторинг кода приложения;
- style — исправление опечаток, форматирования;
- docs — всё, что касается документации;
- test — всё, что связано с тестированием;
- merged, fix conflict — слияние, решение конфликта.
21. image upload
- Just drag and drop your image from your local pc to github readme in editable mode.
- You can create a .github/images directory in your repo and add all your assets there. Assets added here will be available on
https://raw.githubusercontent.com/{github_user_name}/{repo_name}/{branch}/.github/images/{asset_name}.{asset_extension}
Link in README.md:
![Alt Text](/assets/{asset_name}.{asset_extension})
22. EXAPLES
22.1. branch
git checkout origin/another_branch
git checkout master git merge hotfix
22.2. misstake
git reset –hard
git commit –amend -m "asd"
git reset –hard a43e2d13 git push origin development –force
22.3. tags
git tag 1.6.1 -m 'Release 1.6.1'
git push origin [tagname]
git push origin tag <tagname>
git push –tags
git push origin v0.1
git tag -d 1.7.0
git push origin :refs/tags/1.7.0
git show 1.6.1 git chechout <tag_name>
22.4. all
ref~ is shorthand for ref~1 and means the commit's first parent ref^1 ref^2 - two parents for merge commit
git diff-tree –name-only -r <commit_id> git diff HEAD^ HEAD
git blame -w -L 1,2 [filename]
git shortlog git shortlog -s - only users
git pull = git fetch + git merge git pull –rebase = git fetch + git rebase - clear changes
git checkout - reset file to latest commit or stagged state
git status - Displays paths that have any differences
git config –global –list git config –list - repository config
git clone git://github.com/vogella/gitbook.git git - default protocol 9148 port git clone http://github.com/vogella/gitbook.git clone via HTTP git clone ssh://git@github.com/vogella/gitbook.git git - name for ssh URL for remote: git@github.com/vogella/gitbook.git
git remote show origin - get a full list of Remote references are references (pointers) in your remote repositories, including branches, tags, and so on. git ls-remote origin - like above git remote -v
### Stagging area ### git add [path] -add to staging area git reset [path] -remove staging area git diff –cached -shows the differences between the staging area and the last commit git add -n . - on’t actually add the file(s), just show if they exist and/or will be ignored.
#clean git reset –hard - clean stagging area but do not touch untracked files git clean -fdx - remove untracked files -f force -d directories -x hidden files
#reset to origin git fetch origin git reset –hard origin/master git checkout master
git reset HEAD~1 - move HEAD and branch pointer - do nothing with untracked files Reset Branch pointer Working tree Staging area soft Yes No No mixed (default) Yes No Yes hard Yes Yes Yes
git reflog - show HEAD movements and found reseted commits
git show HEAD:./pom.xml -show file
Create patch:
echo "new content for test01" >test01
git add . git commit -m "first commit in the branch"
git format-patch origin/master or git format-patch -3 HEAD - for last 3 commits Apply patch:
git checkout master
git apply 0001-First-commit-in-the-branch.patch
git add . git commit -m "apply patch"
rm 0001-First-commit-in-the-branch.patch #short git am *.patch -order in which the patches are applied by specifying them on the command line.
#remove last commit git reset –hard HEAD~ git commit –amend git push -f origin master
#fix detached HEAD git checkout master
#Subtree https://help.github.com/articles/about-git-subtree-merges/ git remote add -f test-subtree git@github.com:Anoncheg1/test-subtree.git #–no-commit perform the merge but pretend the merge failed and do not autocommit
git merge -s ours –squash –no-commit –allow-unrelated-histories test-subtree/master git read-tree –prefix=test-subtree/ -u test-subtree/master
#pull changed subtree in parent git pull –allow-unrelated-histories –squash -s subtree test-subtree master
#push subtree from parent ???
git submodule add [URL to Git repo] git submodule init git submodule update –remote -remote if you need branches. updates the working tree to the commit described by the branch cd [submodule directory] git checkout master git pull
git clone –recursive
#push submodule from parent #cd submodule git status - check that we on master git checkout master - if detached HEAD mode commit submodule cd parent commit parent git submodule update
#commit main git submodule update git commit
23. USE CASE
23.1. see changes
- git diff myfile.txt # haven't git added yet
- git diff –cached myfile.txt # already added
23.2. branches
remove commits to another branch
- git checkout -b new
- git checkout old
- git reset –hard commit
- git push origin –force
remove commits from remote branch
merge range of commits
- cherry-pick
- git checkout old_or_master
- git checkout -b new_branch
- git cherry-pick a..e # from development
23.3. explore unknown repo
- git branch -a (all or -r remote)
- git log –graph –oneline
- fetch/push: git remote -v
- authors: git shortlog –summary –numbered –email –since "2 year ago" or git shortlog -sne
- git tag # get all tags and versons
23.4. pull forced
git reset –hard git pull
23.5. delete all hisotry / remove all commits
git checkout –orphan latest_branch git add -A git commit -am "commit message" git branch -D master git branch -m master -rename current branch to master git push -f origin master git branch -u origin/master master - to track remote
git –work-tree="." pull –allow-unrelated-histories git merge git rebase
23.6. delete commits after
- git reset –hard commit
- git push origin HEAD –force ??????
- git push origin +HEAD:development
23.7. check if working tree has local changes
one of:
- git status -s
- git diff –name-only
git diff HEAD
git status -u - display untacked files
23.8. seach
in files git grep WHAT
- -n add line number
- –count print only sum occurances
- –heading –break - more readable
in content of commits git log -S WHAT –oneline
23.9. merge changes in big priject - instruction
- Create a new dev branch
- Do your work on local dev branch
- Push dev branch from your local to central git repository
- Once your work is done, merge dev branch to master
- Finally, delete the dev branch from both local and central git repository
s
- git checkout -b my_branch
- git commit -m " "
- git push –set-upstream origin my_branch
- git checkout development
- git merge my_branch
- git branch -d dev
- git branch -d -r origin/dev
- git push
23.10. restore file to HEAD
git restore file
23.11. get all authors
- git shortlog -sn –since "2 year ago"
23.12. git move between commits
- git checkout HEAD^
- git switch - and/or git checkout master
24. join commits together, merge commits, squash commits, Squash commits into one
merge two last commits together:
git rebase --interactive HEAD~2
or
git merge --squash bigix # Takes all commits from the bugfix branch and groups it for a 1 commit with your current branch.
merge in history:
: git rebase -i <commit_hash> # after which others will be squashed select commits that will be squashed
; git push –force-with-lease
25. humor
when the Internet connection lost: "Looks like something went wrong!"
26. Troubleshooting
You have divergent branches and need to specify how to reconcile them.
- There is a merge conflict, you should one of:
- git merge or git pull –no-ff # create merge
- git rebase or git pull –rebase # temporarily removes commits from our local branch and do fast-forward
- This is the default setting. It means that git pull will use a merge strategy to combine the changes. This creates a new merge commit that combines the changes from the remote branch with your local branch.
- This configuration tells git pull to use a rebase strategy instead of a merge. This means that your local changes will be replayed on top of the remote changes, creating a linear history with no merge commits.
- This configuration tells git pull to only perform fast-forward merges, which means that the local branch will be updated only if it can be fast-forwarded to the remote branch. If there are any divergent changes, git pull will fail and you will need to resolve the conflicts manually.
27. status badge
![example workflow](https://github.com/github/docs/actions/workflows/main.yml/badge.svg)
select branch:
![example branch parameter](https://github.com/github/docs/actions/workflows/main.yml/badge.svg?branch=feature-1)
event:
![example event parameter](https://github.com/github/docs/actions/workflows/main.yml/badge.svg?event=push) ![example event parameter](https://github.com/github/docs/actions/workflows/main.yml/badge.svg?event=release)
28. python bots
- python/miss-islington
- python/bedevere
- python/the-knights-who-say-ni
29. https://jonas.github.io/tig/
- tig log [options] [revisions] [–] [paths]
- .
- tig show [options] [revisions] [–] [paths]
- Open diff view using the given git-show(1) options.
- tig reflog [options] [revisions]
- .
- tig blame [options] [rev] [–] path
- given file annotated by commits
- tig grep [options] [pattern]
- .
- tig refs [options]
- .
- tig stash [options]
- tig status
- .
- tig <
- .
- tig +N
- show +2 = +1 commit from HEAD
29.1. Keybindings
View Switching
- m Switch to main view.
- d Switch to diff view.
- l Switch to log view.
- p Switch to pager view.
- t Switch to (directory) tree view.
- f Switch to (file) blob view.
- g Switch to grep view.
- b Switch to blame view.
- r Switch to refs view.
- y Switch to stash view.
- h Switch to help view
- s Switch to status view
- c Switch to stage view