Common git operations » History » Revision 20
Revision 19 (cryptogopher, 2025-05-18 22:10) → Revision 20/22 (cryptogopher, 2025-05-19 00:32)
h1. Common git operations
{{>toc}}
Prerequisites:
<pre>
cd ~/plugins/issue_recurring
</pre>
h2. Issue/pull request resolution in separate branch
h3. Create separate branch for issue
# Checkout and update master:
<pre>
$ git checkout master
$ git pull
</pre>
# Create, checkout new branch and push it to remote (so it will be tracked and replicated on it.michalczyk.pro):
<pre>
$ git checkout -b issueN
$ git push -u origin issueN
</pre>
# Reload all files open in vim:
<pre>
:bufdo! e
</pre>
h3. Checkout pull request locally (for editing, testing etc.)
"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
# Fetch pull request based on its number into new branch and switch to new branch:
<pre>
$ git fetch origin pull/N/head:prN
$ git checkout prN
</pre>
# (optionally) Push newly created branch:
<pre>
git push -u origin prN
</pre>
h3. Merge issue/pull request branch into master
# Push uncommited changes on issue branch.
# Checkout and update master:
<pre>
$ git checkout master
$ git pull
</pre>
# Merge adding comment _closes #N_ (for issue branch), optionally view commits and push issueN/prN branch:
<pre>
$ git merge issueN
$ git log origin/master..HEAD
$ git push
</pre>
# Delete merged branch from local and remote:
<pre>
$ git branch -d issueN
$ git push origin :issueN
</pre>
# Verify:
<pre>
$ git branch -a
</pre>
h3. Merge PR from forked repository fork that is behind master (divergent branch)
Add forked remote with fork and fetch branches:
<pre>
git remote add someuser https://github.com/someuser/somerepo.git
git fetch someuser
git branch -a
</pre>
Squash PR commits to separate branch for further editing:
<pre>
git checkout -b prN
git merge --squash someuser/remote-branch-name
</pre>
Commit, Commit setting author properly:
<pre>
</pre>
h2. Release
h3. Move tag to different commit (e.g. after fixing some mistake)
# Remove tag from remote (if it has been pushed):
<pre>
git push origin :refs/tags/1.3
</pre>
# Force replacement of existing tag with one referencing most recent commit:
<pre>
git tag -fa 1.3
</pre>
# Push:
<pre>
git push origin 1.3
</pre>
h2. Other
h3. Change remote URL from HTTPS to SSH (required by Github's no-password policy)
# Check current URL:
<pre>
git remote -v
</pre>
# Change to SSH:
<pre>
git remote set-url origin git@github.com:cryptogopher/issue_recurring.git
</pre>