đŸ’»
Cheatsheets
  • Most Useful Command Line Tools: 50 Cool Tools to Improve Your Workflow, Boost Productivity, and More
  • 7_tips_to_reverse_engineer_javascript
  • Configuring a Repl
  • How to create your command-line program (CLI) with NodeJS and Commander.js | by Duc N. | JavaScript
  • replit Node.JS 24/7 Project Hoster
  • cheatsheets
  • Alacritty, Tmux, and Vim
  • amethyst
  • Android
  • Installing Arch Linux
  • Arch Linux
  • aria2
  • bin
  • bspwm
  • Chocolately Notes
  • command_line_pipes
  • CSS Grid
  • curl
  • The curl guide to HTTP requests
  • Docker
  • Easymotion
  • Emmet
  • Favorite figlet fonts
  • FFMPEG
  • figlet
  • File Serve
  • File Transfer
  • fish shell
  • Front End Dev Links
  • How to use Git.io to shorten GitHub URLs and create vanity URLs
  • Git
  • Downloading a Tarball from GitHub
  • Make Infinite Gmail Addresses For One Inbox
  • How To Use GPG on the Command Line
  • guide_to_fish_completions
  • Homebrew
  • How to clean Arch Linux
  • HTML5 Boilerplate
  • Install
  • All the keyboard shortcuts you’ll ever need for Safari on iPad
  • iosevka
  • iPhone
  • ish (iOS)
  • Javascript Notes
  • jq
  • Jupyter Notebooks
  • Lettering
  • lf-wiki
  • lf
  • Command Line
  • Adding a swapfile after a clean installation without swap partition
  • mac_bluetooth_issues
  • Mac Terminal
  • maim
  • markdown-sample
  • Markdown Notes
  • Images in README.md Markdown Files
  • Organizing information with tables
  • md_cheatsheet
  • NiftyWindows Help
  • nix
  • Justin Restivo - A Portable Text Editor: Nix <3 Neovim
  • NPM
  • neovim configuration
  • Pastery
  • Powershell
  • Table of Basic PowerShell Commands | Scripting Blog
  • Powershell Modules
  • Puppeteer
  • Python
  • rclone-colab
  • replit
  • Hi there, I'm Raju Ghorai - a.k.a. [coderj001]
  • Scriptable
  • Servor
  • Replacing Postlight’s Mercury scraping service with your self-hosted copy
  • Shell Scripts
  • skhd
  • Spicetify
  • SSH
  • SurfingKeys
  • tar
  • Terminal Web Browser Docker
  • Text Generators
  • tmux shortcuts & cheatsheet
  • unicode
  • VIM
  • VIM Diff
  • vi Complete Key Binding List
  • 8 Essential Vim Editor Navigation Fundamentals
  • Vim Shortcut Keys
  • Vite
  • VNC
  • web-servers
  • Web Server
  • Windows Command Line
  • Writeguard
  • WSL Cheatsheet
  • youtube-dl
  • zsh Plugins
  • zspotify
Powered by GitBook
On this page
  • get a file from another branch
  • Replace master branch with another branch
  • git status shows modified files because of CRLF and LF
  • Cloning and Using Pull Requests
  • clone into a non-empty folder
  • Diff master and a branch
  • Commit another change without editing the commit message

Was this helpful?

Git

PreviousHow to use Git.io to shorten GitHub URLs and create vanity URLsNextDownloading a Tarball from GitHub

Last updated 2 years ago

Was this helpful?

get a file from another branch

git checkout branch-name path/to/file.ext

Replace master branch with another branch

Taken from

You should be able to use the “ours” merge strategy to overwrite master with seotweaks like this:

git checkout master
git pull
git checkout seotweaks
git merge -s ours master
git checkout master
git merge seotweaks

The first two steps are a useful precaution to ensure your local copy of master is up-to-date. The result should be that your master is now essentially seotweaks.

(-s ours is short for --strategy=ours)

From the docs about the ‘ours’ strategy:

This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of side branches. Note that this is different from the -Xours option to the recursive merge strategy.

Update from comments: If you get fatal: refusing to merge unrelated histories, then change the second line to this: git merge --allow-unrelated-histories -s ours master

git status shows modified files because of CRLF and LF

I had an issue where hundreds of line endings were modified by some program and git diff listed all source files as changed. After fixing the line endings, git status still listed the files as modified.

I was able to fix this problem by adding all files to index and then resetting the index.

git add -A

git reset

core.filemode was set to false.

Git features a ‘remove’ command, git rm. You can use it to remove files from git’s tracking cache, like so:

PowerShell

git rm --cached

|

1

|

git rm --cached < filename>

|

The above command is for a specific file. It will take effect with your next commit. It’s a good idea for you to commit any pending changes you have before you start this process. If you have many files and/or folders (for instance, your /bin and /obj folders in a .NET project) that you need to clean up from your repository, you can use the following commands to remove them from the index (cache):

PowerShell

git rm -r --cached .

|

1

|

git rm -r --cached .

|

The -r switch makes the command recursive from the current path. Next, add back all of the files you do want to track, using:

PowerShell

git add .

|

1

|

git add .

|

Cloning and Using Pull Requests

Getting the PR code

  1. Make note of the PR number. For example, Rod's latest is PR #37: https://github.com/Psiphon-Labs/psiphon-tunnel-core/pull/37

  2. Fetch the PR's pseudo-branch (or bookmark or rev pointer whatever the word is), and give it a local branch name. Here we'll name it pr37:

$ git fetch upstream pull/37/head:pr37
  1. Switch to that branch:

$ git checkout pr37
  1. Compile and test.

If the PR code changes and you want to update:

# Do this while in the pr37 branch
$ git pull upstream pull/37/head

(I try to avoid pull and instead use fetch+merge, but... I don't know how to do it for this.)

Merging the PR

First, checkout the upstream master code:

You'll only do this the first time -- it creates the local upstream_master branch, tracks it to upstream_master, and switches to the branch:

$ git checkout -t -b upstream_master upstream/master

After the first time you'll just do:

$ git checkout upstream_master

Now merge the PR:

$ git merge pr37

NOTE: You should edit the merge commit message to reference the PR (using, say #37 in it).

Now push:

$ git push upstream HEAD:master

(You can't just git push because your local branch name is different than the remote.)

Done! Refresh the Github PR page and you'll see that the PR is now merged+closed.

clone into a non-empty folder

git init     
git remote add origin PATH/TO/REPO     
git fetch     
git checkout -t origin/master -f

or this maybe

git init
git remote add origin PATH/TO/REPO
git fetch
git reset origin/master  # Required when the versioned files existed in path before "git init" of this repo.
git checkout -t origin/master

Diff master and a branch

git diff master branch_number

Commit another change without editing the commit message

For when you forget to make an additional change and you've already committed

git commit --amend --no-edit
<p class="chad">This is a sample test</p>
foo@bar:~$ whoami
foo

Then, commit your changes and your files that would have been ignored if you’d had the right .gitignore in place from the start should no longer be tracked. Yay! If you’re interested, or if this approach doesn’t work for you, there are a few variations on how you might achieve the same result listed in .

It's not immediately obvious how to pull down the code for a PR and test it locally. But it's . (This assumes you have a remote for the main repo named upstream.)

You can use the Github web interface, but there's a problem: If the pull-requester changes their master (or whatever they're PRing from) between the time you test and the time you merge, then you'll be merging code that you haven't reviewed/tested. So let's do it on the command line.

stackoverflow
this StackOverflow thread
pretty easy
TOCTOU