Skip to content

Instantly share code, notes, and snippets.

@bguiz
Created December 13, 2017 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bguiz/3cac9b12039244cbac52f7d0b51a197a to your computer and use it in GitHub Desktop.
Save bguiz/3cac9b12039244cbac52f7d0b51a197a to your computer and use it in GitHub Desktop.

Why

  • You want to do a minor edit to files on another branch
  • The copy of the git repo that you have locally is in a state that is too much effort to clean up/ revert/ stash etc to bother

How

  • simply clone the repo in a different folder
  • but this clone is minimal, so it's much faster
    • only clone the branch you are interested in
    • only clone the latest 2 commits
  • commit and push
git clone -b ${GIT_BRANCH} --single-branch --depth=2 ${GIT_REMOTE} ${FOLDER_TO_CLONE_INTO}
cd ${FOLDER_TO_CLONE_INTO}
git log # verify that you're at the right starting point
# edit relevant files
git add -p
# Either:
git commit --amend
git push origin ${GIT_BRANCH} --force
# Or:
git commit
git push origin ${GIT_BRANCH}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment