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