Home> Programming> Gitology…

Gitology

   This page contains my Git notes; some routine stuff, some ticky stuff, and the gotchas!
  1. Cloneology
    1. If repo exists: say, my_repo.
      • If it's the first one goto to Step 3.
      • It it's an additional one got to Step 4.
    2. Create a Repo in GitLab: say, my_repo.
    3. Set up SSH Permissions: You can find the details online, but in a nutshell it amounts to doing an
      $ ssh-keygen -t rsa -b 4096 -C "<user-name@github-registered-email-address>"
      and then copying the contents of the ~/.ssh/id_rsa.pub file to GitHub, via, the New SSH Key button under the SSH and GPG Keys option on your Settings page.
    4. Clone it:
      $ git clone git@github.com:rubiculite/my_repo.git
      If you have submodules, then it would be,
      $ git clone --recursive git@github.com:rubiculite/my_repo.git
      If you forget to do that, then it's a little tricker, but naively just do,
      my_repo$ git submodule update --init
      or if there are nested submodules do,
      my_repo$ git submodule update --init --recursive
      However, what's not mentioned is it leaves your submodule(s) in a defunct state; in short, go to the too the submodule(s) and do a,
      my_repo$ git checkout master

      †Example,
      my_repo$ git branch * (HEAD detached at ba5179f) master my_repo$
      So switching to master fixes the problem.
  2. Branchology
    1. Seeing Branches
      • locally
        my_repo$ git branch
      • remote
        my_repo$ git branch -a
      • fetching
        my_repo$ git fetch --all my_repo$ git branch -a
    2. Creating a Branch
      my_repo$ git branch my_repo$ git push -u origin
    3. Deleting a Branch
      my_repo$ git branch -d my_repo$ git push origin --delete
    4. Merge File Into Current Branch
      my_repo$ git checkout <branch> <file> my_repo$ git commit -m "Merged file from to "
  3. Commitology
    1. Checking Commit Status
      git status
    2. Updating Local Repo
      git pull
    3. Commiting Files
      git add <file_1> <file_2> … <file_n> git commit -m "Commit Comments"
    4. Making changes on a specific commit.
      • See above link for details.
  4. Taggology
    my_repo$ git tag v1.0 my_repo$ git push origin --tags
  5. Submoduleology
    1. Removing a Submodule
      • Delete the relevant line from the .gitmodules file.
      • Delete the relevant section from .git/config.
      • Run git rm --cached pathtosubmodule (no trailing slash).
      • Commit the superproject.
      • Delete the now untracked submodule files.
    2. Adding a Submodule
      • To create a submodule use,
        <repo-root>$ git submodule add <repo-source> <path>/<custom-name>
        Example:
        my_repo$ git submodule add git@github.com:rubiculite/display_mockup.git apps/static/main/display_mockup Cloning into 'apps/static/main/display_mockup'... remote: Counting objects: 291, done. remote: Total 291 (delta 0), reused 0 (delta 0), pack-reused 291 Receiving objects: 100% (291/291), 3.81 MiB | 3.27 MiB/s, done. Resolving deltas: 100% (155/155), done. my_repo$
    3. Moving a Submodule
      This simplest way is to do steps 5.1 and 5.2 above, unless you have version 1.85 or greater (1.9.3 or newer is best, as it has the appropriate bug fixes) then git mv works as expected: i.e.,
      git mv <old-path>/<submodule> <new-path>/<submodule>
  6. Clobberology To overwrite a file from master while in another branch.
    git fetch git checkout origin/master <filepath>
  7. Fetchology To fetch a file from one repo into another's top-directory do...
    git fetch <remote> git checkout FETCH_HEAD:<path-to-remote-file> -- <file>
    Example: Fetching hello.c from rubiculte's waterfall_plotter repo into my_repo.
    my_repo$ git fetch git@github.com:rubiculite/waterfall_plotter.git my_repo$ git checkout FETCH_HEAD:docs/pics -- waterfall_plotter_with_xhairs.png
    and we have the file!
    my_repo$ git status On branch master Your branch is up to date with 'origin/master'. Changes to be committed: (use "git reset HEAD ..." to unstage) new file: waterfall_plotter_with_xhairs.png my_repo$
    NB: You will have to experiment with the exact syntax if you want the file in a specific directory, or just experiment with `git mv` vs. `mv`.

Home> Programming> Gitology…
___________
Last Updated: Mon 6 May 2019 19:53:07 CDT