refactor: finish moving ssh-* scripts to own installers
[webi-installers/.git] / git / README.md
1 ---
2 title: Git
3 homepage: https://git-scm.com
4 tagline: |
5   git: --fast-version-control
6 ---
7
8 To update or switch versions, run `webi git@stable` (or `@v2.30`, `@beta`, etc).
9
10 ## Cheat Sheet
11
12 > Git is a fast, scalable, distributed revision control system with an unusually
13 > rich command set that provides both high-level operations and full access to
14 > internals.
15
16 Github's [Git 'Hello World'](https://guides.github.com/activities/hello-world/)
17 is a good place to get started if you're new to git.
18
19 ### How to commit files
20
21 ```bash
22 git add ./path/to/file1
23 git add ./path/to/file2
24 git commit -m "my summary for this commit"
25 ```
26
27 ### How to ignore common files
28
29 In your project repository create a `.gitignore` file with patterns of fies to
30 ignore
31
32 ```txt
33 .env*
34 *.bak
35 *.tmp
36 .*.sw*
37 ```
38
39 ### How to create a branch
40
41 This will branch from the branch you're currently on.
42
43 ```bash
44 git checkout -b my-branch-name
45 ```
46
47 ### How to rebase by default
48
49 ```bash
50 git config --global pull.rebase true
51 ```
52
53 ### How to rebase
54
55 > To "rebase" simply means to undo any of your changes, apply updates from
56 > another branch first, and then replay your changes.
57
58 Rebase when fetching new updates
59
60 ```bash
61 git pull --rebase origin master
62 ```
63
64 Rebase a feature branch from master before a merge
65
66 ```bash
67 # update master
68 git fetch
69 git checkout master
70 git pull
71
72 # go back to your feature branch
73 git checkout my-feature
74
75 # start the rebase
76 git rebase master
77
78 # fix conflicts if you need to, and then continue
79 git add ./my-merged-file
80 git rebase --continue
81 ```
82
83 ### How to authenticate git with deploy tokens
84
85 Abbreviated from
86 [The Vanilla DevOps Git Credentials & Private Packages Cheatsheet](https://coolaj86.com/articles/vanilla-devops-git-credentials-cheatsheet/):
87
88 First, update `.gitconfig` to handle each type of git URL (git, ssh, and http)
89 as https:
90
91 ```bash
92 git config --global url."https://api@github.com/".insteadOf "https://github.com/"
93 git config --global url."https://ssh@github.com/".insteadOf "ssh://git@github.com/"
94 git config --global url."https://git@github.com/".insteadOf "git@github.com:"
95 ```
96
97 Next, create a `.git-askpass`:
98
99 ```bash
100 echo 'echo $MY_GIT_TOKEN' > $HOME/.git-askpass
101 chmod +x $HOME/.git-askpass
102 ```
103
104 Finally, add the following ENVs to your deployment environment:
105
106 ```bash
107 GIT_ASKPASS=$HOME/.git-askpass
108
109 # Relpace xxxx... with your deploy token
110 MY_GIT_TOKEN=xxxxxxxxxxxxxxxx
111 ```
112
113 In the case of Github it may be useful to create a read-only deploy user for
114 your organization.
115
116 This can work with Docker, Github, Gitlab, Gitea, CircleCI, and many more.