13 January 2023
I created this guide based on my experience with git. This is the first thing I look into for anything related to git followed by git documentation.
Checking out a PR
I prefer to use
gh command line tool but since it always requires a token, working with it on a remote session is hard. You've to manually paste your access token to a remote instance. Here's how you achieve the same using git.
$ git fetch origin pull/<id>/head:<branch-name> $ git checkout branch-name
I've been working with worktree for a while now and here's my snippets for working on this.
- For me, all the branch leaves under the
wtreedirectory under the repo.
# clone the repo $ git clone --bare <repo-url> <project-name> # add a branch $ git worktree add -b <branch-name> wtree/<branch-name> # delete a branch $ git worktree remove <branch> # pulling changes from a remote branch $ git worktree add -b <branch-name> wtree/<branch-name> # pull the changes on that branch $ git pull origin <branch-name> # How to know what are the available branches in your remote repo? $ git ls-remote --heads origin
# deleting a branch locally $ git branch -d <branch-name> # only delete if it's merged into current branch $ git branch -D <branch-name> # force delete even if it's not merged # deleting a remote branch $ git push origin --delete <branch-name>
# adding a remote $ git remote add <repo-url> # removing a remote $ git remtoe remove <repo-url> # changing the URL of the remote $ git remote set-url <remote-name> <repo-url> # remote-name (origin,upstream etc.)
- git diff is something that you'll check almost everytime before creating a PR. Here are some commands that I use with git diff on a very frequent basis.
You can list the names of all those files where you've made any changes.
$ git diff --name-only
- Now you can do multiple things with this, you can open all the files where you've made any changes using the following command.
$ git diff --name-only | xargs hx
Note: Helix is my primary editor and I love it.
- You can also search within your diff for patterns using the following command.
$ rg gcs_credentials (git diff --name-only)