Common git operations » History » Version 20
cryptogopher, 2025-05-19 00:32
1 | 1 | cryptogopher | h1. Common git operations |
---|---|---|---|
2 | |||
3 | 5 | cryptogopher | {{>toc}} |
4 | 1 | cryptogopher | |
5 | Prerequisites: |
||
6 | <pre> |
||
7 | cd ~/plugins/issue_recurring |
||
8 | </pre> |
||
9 | |||
10 | 14 | cryptogopher | h2. Issue/pull request resolution in separate branch |
11 | 1 | cryptogopher | |
12 | 2 | cryptogopher | h3. Create separate branch for issue |
13 | 3 | cryptogopher | |
14 | 2 | cryptogopher | # Checkout and update master: |
15 | <pre> |
||
16 | $ git checkout master |
||
17 | $ git pull |
||
18 | </pre> |
||
19 | # Create, checkout new branch and push it to remote (so it will be tracked and replicated on it.michalczyk.pro): |
||
20 | <pre> |
||
21 | $ git checkout -b issueN |
||
22 | $ git push -u origin issueN |
||
23 | </pre> |
||
24 | 9 | cryptogopher | # Reload all files open in vim: |
25 | 7 | cryptogopher | <pre> |
26 | :bufdo! e |
||
27 | </pre> |
||
28 | |||
29 | 16 | cryptogopher | h3. Checkout pull request locally (for editing, testing etc.) |
30 | |||
31 | 17 | cryptogopher | "Github docs":https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/checking-out-pull-requests-locally#modifying-an-inactive-pull-request-locally |
32 | |||
33 | 16 | cryptogopher | # Fetch pull request based on its number into new branch and switch to new branch: |
34 | <pre> |
||
35 | $ git fetch origin pull/N/head:prN |
||
36 | $ git checkout prN |
||
37 | </pre> |
||
38 | # (optionally) Push newly created branch: |
||
39 | <pre> |
||
40 | git push -u origin prN |
||
41 | </pre> |
||
42 | |||
43 | 13 | cryptogopher | h3. Merge issue/pull request branch into master |
44 | 2 | cryptogopher | |
45 | # Push uncommited changes on issue branch. |
||
46 | 1 | cryptogopher | # Checkout and update master: |
47 | <pre> |
||
48 | $ git checkout master |
||
49 | $ git pull |
||
50 | </pre> |
||
51 | 13 | cryptogopher | # Merge adding comment _closes #N_ (for issue branch), optionally view commits and push issueN/prN branch: |
52 | 1 | cryptogopher | <pre> |
53 | $ git merge issueN |
||
54 | 13 | cryptogopher | $ git log origin/master..HEAD |
55 | 5 | cryptogopher | $ git push |
56 | 10 | cryptogopher | </pre> |
57 | # Delete merged branch from local and remote: |
||
58 | 11 | cryptogopher | <pre> |
59 | $ git branch -d issueN |
||
60 | 12 | cryptogopher | $ git push origin :issueN |
61 | </pre> |
||
62 | # Verify: |
||
63 | <pre> |
||
64 | $ git branch -a |
||
65 | </pre> |
||
66 | 11 | cryptogopher | |
67 | 20 | cryptogopher | h3. Merge PR from forked repository that is behind master (divergent branch) |
68 | 19 | cryptogopher | |
69 | 20 | cryptogopher | Add forked remote and fetch branches: |
70 | 19 | cryptogopher | <pre> |
71 | git remote add someuser https://github.com/someuser/somerepo.git |
||
72 | git fetch someuser |
||
73 | git branch -a |
||
74 | </pre> |
||
75 | |||
76 | Squash PR commits to separate branch for further editing: |
||
77 | <pre> |
||
78 | git checkout -b prN |
||
79 | git merge --squash someuser/remote-branch-name |
||
80 | </pre> |
||
81 | |||
82 | 20 | cryptogopher | Commit, setting author properly: |
83 | 19 | cryptogopher | <pre> |
84 | </pre> |
||
85 | 11 | cryptogopher | |
86 | 5 | cryptogopher | h2. Release |
87 | 4 | cryptogopher | |
88 | h3. Move tag to different commit (e.g. after fixing some mistake) |
||
89 | |||
90 | # Remove tag from remote (if it has been pushed): |
||
91 | <pre> |
||
92 | git push origin :refs/tags/1.3 |
||
93 | </pre> |
||
94 | # Force replacement of existing tag with one referencing most recent commit: |
||
95 | <pre> |
||
96 | git tag -fa 1.3 |
||
97 | </pre> |
||
98 | # Push: |
||
99 | <pre> |
||
100 | git push origin 1.3 |
||
101 | </pre> |
||
102 | 18 | cryptogopher | |
103 | |||
104 | h2. Other |
||
105 | |||
106 | h3. Change remote URL from HTTPS to SSH (required by Github's no-password policy) |
||
107 | |||
108 | # Check current URL: |
||
109 | <pre> |
||
110 | git remote -v |
||
111 | </pre> |
||
112 | # Change to SSH: |
||
113 | <pre> |
||
114 | git remote set-url origin git@github.com:cryptogopher/issue_recurring.git |
||
115 | </pre> |