Skip to content

Instantly share code, notes, and snippets.

@bonsi
Last active February 15, 2017 07:42
Show Gist options
  • Save bonsi/f80a2b8c4f62dc538ba42fc884b769de to your computer and use it in GitHub Desktop.
Save bonsi/f80a2b8c4f62dc538ba42fc884b769de to your computer and use it in GitHub Desktop.
Git commands

Branches

How to check out a remote Git branch

git fetch
git checkout test

Forks

How to contribute to an open-source GitHub project using your own fork

  • Fork the repo
  • Clone it locally:
    git clone [email protected]:bonsi/laradock.git
  • Keep it in sync with the source:
    git remote add upstream https://github.com/laradock/laradock.git
  • Merge upstream changes:
    git checkout development
    git fetch upstream
    git merge upstream/development
    git push origin development
  • Create a new feature branch to work on:
    git checkout -b my-feature-name
  • Do your thing:
    git add something
    git commit -m "Whoa!"
    git push origin my-feature-name
  • Create a PR on github

Submodules

Add

  • git submodule add <url>https://github.com/bonsi/repo.git [-b <branch>] [path]

Update

  • git submodule update --recursive --remote

Remove

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes via command line using:
    git add .gitmodules
  • Delete the relevant section from .git/config
  • Run
    git rm --cached path/to/submodule Don't include a trailing slash -- that will lead to an error.
  • Run
    rm -rf .git/modules/submodule_name
  • Commit the change
  • Delete the now untracked submodule files:
    rm -rf path/to/submodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment