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