Difference between revisions of "IT-SDK-Git"
Jump to navigation
Jump to search
(→Remote) |
(→Fetch & Pull & Push) |
||
| Line 180: | Line 180: | ||
</pre> | </pre> | ||
| + | ==Remote== | ||
| + | <pre class="code"> | ||
| + | git remote -v # View existing remotes | ||
| + | git remote rename origin destination # Change remote name from 'origin' to 'destination' | ||
| + | --- | ||
| + | git remote prune origin --dry-run | ||
| + | git remote prune origin | ||
| + | </pre> | ||
==Fetch & Pull & Push== | ==Fetch & Pull & Push== | ||
<pre class="code"> | <pre class="code"> | ||
| − | git fetch | + | git fetch # Download new data (commits, files, and refs.) from a remote-repository into local-repository. |
| − | git pull | + | git fetch --prune # Remove remote branches that not longer have a counterpart. |
| − | git pull --rebase origin master | + | --- |
| − | git push --force-with-lease | + | git pull # Download new data (commits, files, and refs.) from a remote-repository into local-repository and integrate the new data in working-files. |
| + | git pull --rebase origin master # get changes from remote master. And commit it for local/user commit. | ||
| + | --- | ||
| + | git push # Upload local-repository content to a remote-repository. | ||
| + | git push --force-with-lease # To avoid overwrite history from rebase, Lease entsure that history dokumented. | ||
</pre> | </pre> | ||
Revision as of 16:58, 1 February 2021
Resource
- https://help.github.com/en/github/using-git
- https://www.atlassian.com/git/tutorials/setting-up-a-repository
- https://fedoraproject.org/wiki/Git_quick_reference
- https://www.git-tower.com/learn/git/ebook/en/command-line/advanced-topics/merge-conflicts
- https://hackernoon.com/understanding-git-index-4821a0765cf
- https://docs.gitlab.com/ee/topics/git/numerous_undo_possibilities_in_git/
- Git-Branching-Game: https://learngitbranching.js.org/
- https://www.toptal.com/software/trunk-based-development-git-flow
- Cheat-Sheet: https://github.github.com/training-kit/downloads/de/github-git-cheat-sheet/
- Cheat-Sheet: https://www.atlassian.com/git/tutorials/atlassian-git-cheatsheet
- https://www.gitignore.io
Setting
ssh
type %userprofile%\.ssh\id_rsa.pub | clip cat %userprofile%\.ssh\id_rsa.pub | clip
ssh -T git@github.com ssh -T git@bitbucket.org git remote set-url origin git@github.com:username/your-repository.git
Config
git config --list git config --global --edit ... git config --global http.proxy $PROXY_URL git config --global https.proxy $PROXY_URL ... git config --global user.name "Samer Hijazi" git config --global user.email "samer.hijazi@samerhijazi.net" ... git config --global core.autocrlf true # Working on Windows, Linux, macOS Maschines. git config --global core.autocrlf false # Working just Windows Machine. git config --global core.longpaths true ... git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin" ... git config --global diff.tool bc git config --global difftool.bc.path "C:/Program Files/Beyond Compare 4/bcomp.exe" ... git config --global merge.tool bc git config --global mergetool.bc.path "C:/Program Files/Beyond Compare 4/bcomp.exe" ... git config --global alias.s status git config --global alias.cp '!git commit -a -m "Update" && git push' ... git commit --amend --reset-author
# https://mattferderer.com/fix-git-self-signed-certificate-in-certificate-chain-on-windows git config --global http.sslVerify false
Credential
- default: no cache at all
- cache: keeps credentials in memory for a certain period of time.
- store: saves the credentials to a plain-text file on disk.
- Mac-Chain: in Mac caches credentials in the secure keychain "osxkeychain".
- Windows-Chain: in Windows caches credentials in the secure keychain.
git config --global credential.helper unset ...........................# remove stored password git config --global credential.helper store ...........................# save entered password git config --global credential.helper cache git config --global credential.helper 'store --file ~/.my-credentials' git config --global credential.helper manager git config --global credential.helper wincred git config --global --edit ... git credential-manager version
Life Cycle
- All-in-One
- Initial
- create files & folders & branches
- del files & folders & braches
- merge branches
- revert changes
All-in-One
git clone https://github.com/samerhijazi/automation.git -b branchname ./local-folder git pull git add README.md git commit -m "First commit" git push -u origin master
Initialisieren
git init --bare # Initial Repo for remote git init # Initial Repo for local ... git remote add origin https://samerhijazi@gitlab.com/samerhijazi/public.git
Clone
git clone https://github.com/samerhijazi/automation.git -b branchname ./local-folder git clone ssh://ssh-w0000000@servername.com/www/htdocs/w0000000/repository/git/projectname.git
Checkout
- HEAD reflects 'git checkout'
git checkout main # checkout main-Branch@HEAD git checkout main^ # moves HEAD 1-commit back from main-Branch git checkout main~4 # moves HEAD 4-commits back from main-Branch git branch -f main HEAD~3 # moves (by force) the main-Branch 3-commits back from HEAD.
Branch
- Checkout
git branch -a # list all branches git branch -r # list all updated branches ... git checkout <exiting-branch> # checkout exiting branch git checkout -b <new-branch> # create a new branch from HEAD and then checkout <new-branch> git checkout -b <new-branch> <existing-branch> # create a new branch from <existing-branch> and then checkout <new-branch> git push --set-upstream origin <new-branch> # Push the current branch and set the remote as upstream
- Rename
git branch -m <old-branch> <new-branch> # To rename a local branch git push origin -u <new-branch> :<old-branch> # To rename a remote branch
- Delete
git branch -d <branch_to_delete> # Delete a branch local git push origin --delete <branch_to_delete> # Delete a branch remote
Merge
git checkout <branch_merge_to> # change to branch where the merge will be done git merge --no-ff <branch_merge_from> # merge <branch_merge_from> in <branch_merge_to> git push ... git merge --abort # returen to the state before starting the merge. git reset --hard # roll back to the commit before the merge.
Taging
git tag -d $(git tag -l) # Delete All local tags. (Optional Recommended) git fetch # Fetch remote All tags. (Optional Recommended) git push origin --delete $(git tag -l) # Delete All remote tags. Pushing once should be faster than multiple times git tag -d $(git tag -l) # Delete All local tags.
Remove & Rename
git checkout <branch-name> git rm -r <file-to-remove> # remove file git mv <filename-old> <filename-new> # rename file git clean -fd # remove directories forced git commit -m "My Massage" git push origin <branch-name>
Reverse (Reset & Revert)
git stash # Save all local changes und remove them from workspace. git fetch # fetch from the default remote, origin ------------------------------------------------------------------------------------------ git reset HEAD~1 # Moves branch reference 1-commit back. git reset * # Undo "git add *" git reset --hard origin/master # Reset your current branch (master) to origin's master ------------------------------------------------------------------------------------------ git revert HEAD # Undo last commit and make ready for remote. ------------------------------------------------------------------------------------------ git clean -f # Remove untracked files. git clean -f -d # Remove untracked files and directories. git clean -f -X # Remove ignored files. git clean -x # Remove ignored as well as non-ignored files.
Remote
git remote -v # View existing remotes git remote rename origin destination # Change remote name from 'origin' to 'destination' --- git remote prune origin --dry-run git remote prune origin
Fetch & Pull & Push
git fetch # Download new data (commits, files, and refs.) from a remote-repository into local-repository. git fetch --prune # Remove remote branches that not longer have a counterpart. --- git pull # Download new data (commits, files, and refs.) from a remote-repository into local-repository and integrate the new data in working-files. git pull --rebase origin master # get changes from remote master. And commit it for local/user commit. --- git push # Upload local-repository content to a remote-repository. git push --force-with-lease # To avoid overwrite history from rebase, Lease entsure that history dokumented.
Git branching model
- src: http://blog.plasticscm.com/2017/04/how-we-do-trunk-based-development.html
- src: https://cloud.google.com/solutions/devops/devops-tech-trunk-based-development
- src: https://medium.com/safetycultureengineering/trunks-are-not-just-for-trees-from-git-flow-to-trunk-based-development-949d580697ef
- src: https://trunkbaseddevelopment.com/
- src: https://nvie.com/posts/a-successful-git-branching-model/
- src: https://medium.com/@patrickporto/4-branching-workflows-for-git-30d0aaee7bf
- src: https://guides.github.com/introduction/flow/index.html
- src: https://www.youtube.com/watch?v=1SXpE08hvGs
- Hauptbraches: master & develop
- Arbeitbraches: feature, release, hotfixes
Branch Feature
git checkout -b myfeature develop ... git checkout develop git merge --no-ff myfeature git branch -d myfeature ... git push origin develop
Branch Release
git checkout -b release-1.2 develop git commit -a -m "Bumped version number to 1.2" ... git checkout master git merge --no-ff release-1.2 git tag -a 1.2 ... git checkout develop git merge --no-ff release-1.2 git branch -d release-1.2
Branch HotFix
git checkout -b hotfix-1.2.1 master git commit -a -m "Bumped version number to 1.2.1" ... git checkout master git merge --no-ff hotfix-1.2.1 git tag -a 1.2.1 ... git checkout develop git merge --no-ff hotfix-1.2.1 git branch -d hotfix-1.2.1
CICD
git --no-pager show -s --format=\'%ae\' # Disaply email address last commit git config user.name # Dispaly email address user