From: AJ ONeal Date: Sat, 4 Jul 2020 07:55:02 +0000 (+0000) Subject: add cheat sheet X-Git-Url: https://git.josue.xyz/?p=webi-installers%2F.git;a=commitdiff_plain;h=2b0e9521df1d3f5be82561f568fdccf9e637112a add cheat sheet --- diff --git a/git/README.md b/git/README.md new file mode 100644 index 0000000..161c779 --- /dev/null +++ b/git/README.md @@ -0,0 +1,103 @@ +--- +title: Git +homepage: https://git-scm.com +tagline: | + git: --fast-version-control +description: | + > Git is a fast, scalable, distributed revision control system with an + > unusually rich command set that provides both high-level operations and full + > access to internals. +--- + +Github's [Git 'Hello World'](https://guides.github.com/activities/hello-world/) +is a good place to get started if you're new to git. + +### How to commit files + +```bash +git add ./path/to/file1 +git add ./path/to/file2 +git commit -m "my summary for this commit" +``` + +### How to ignore common files + +In your project repository create a `.gitignore` file with patterns of fies to +ignore + +```txt +.env* +*.bak +*.tmp +.*.sw* +``` + +### How to create a branch + +This will branch from the branch you're currently on. + +```bash +git checkout -b my-branch-name +``` + +### How to rebase + +Rebase when fetching new updates + +```bash +git pull --rebase origin master +``` + +Rebase a feature branch from master before a merge + +```bash +# update master +git fetch +git checkout master +git pull + +# go back to your feature branch +git checkout my-feature + +# start the rebase +git rebase master + +# fix conflicts if you need to, and then continue +git add ./my-merged-file +git rebase --continue +``` + +### How to authenticate git with deploy tokens + +Abbreviated from +[The Vanilla DevOps Git Credentials & Private Packages Cheatsheet](https://coolaj86.com/articles/vanilla-devops-git-credentials-cheatsheet/): + +First, update `.gitconfig` to handle each type of git URL (git, ssh, and http) +as https: + +```bash +git config --global url."https://api@github.com/".insteadOf "https://github.com/" +git config --global url."https://ssh@github.com/".insteadOf "ssh://git@github.com/" +git config --global url."https://git@github.com/".insteadOf "git@github.com:" +``` + +Next, create a `.git-askpass`: + +```bash +echo 'echo $MY_GIT_TOKEN' > $HOME/.git-askpass +chmod +x $HOME/.git-askpass +``` + +Finally, add the following ENVs to your deployment environment: + +```bash +GIT_ASKPASS=$HOME/.git-askpass + +# Relpace xxxx... with your deploy token +MY_GIT_TOKEN=xxxxxxxxxxxxxxxx +``` + +In the case of Github it may be useful to create a read-only deploy user for +your organization. + +This can work with Docker, Github, Gitlab, Gitea, CircleCI, and many more.