Skip to content

Instantly share code, notes, and snippets.

@xavierchia
Last active October 4, 2023 02:29
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 xavierchia/02d1e89d0a9cf02917449271b9b36b16 to your computer and use it in GitHub Desktop.
Save xavierchia/02d1e89d0a9cf02917449271b9b36b16 to your computer and use it in GitHub Desktop.

Fixup and autosquash

  • git add .
  • git commit --fixup 3050fc0de // Created a fixup commit for 3050fc0de
  • GIT_SEQUENCE_EDITOR=: git rebase -i main --autosquash // Now the fixup commit has been squashed

Cherry picking a range of commits

  • git cherry pick firstCommit^..lastCommit # First and last are inclusive

Working with forked repos

  • git fetch upstream # This will fetch all upstream branches & show on terminal
  • git push origin # This will push all upstream branches to your fork

Removing cached files after adding them to git ignore

  1. git rm -r --cached .
  2. git add .
  3. git commit -m 'Removing ignored files'

Creating new github repo with XCode

  • Create XCode project with git repo
  • Create github repo
  • Follow github instructions
  • git remote add origin https://github.com/xavierchia/TummyTown.git
  • git branch -M main
  • git push -u origin main

Merging the last few commits

- `git reset --soft HEAD~2`
- `git commit -m "new commit message"`
- `git push -f`

Stashing your local changes

- `$ git stash -m "stash message"`
- `$ git stash pop` // to retrieve

Keep local repo same as remote

- `$ git pull`

Amend git commit message

- `$ git commit --amend`
- x to delete stuff
- u is undo
- : and wq to exit

Interactive rebase

- `$ git rebase -i origin/master`

Look for an old commit

- `$ git reflog`
- `$ git reset 'commit number' // Reset to old commit number

Frequently used

- `$ git commit -m "Title" -m "Description .........."`
- `$ git push`
- `# git status`

Deleting a branch

- Deleting a branch LOCALLY
    - `$ git branch -d <branch>`

- Deleting a branch REMOTELY
    - `$ git push <remote> --delete <branch>`
    - Example: `$ git push origin --delete fix/authentication`

Rules to live by for commit messages:

- Don’t end your commit message with a period.
- Keep your commit messages to 50 characters or less. Add extra detail in the extended description window if necessary. This is         located just below the subject line.
- Reference the original issue / issues with #23
- Use active voice. For example, "add" instead of "added" and "merge" instead of "merged".
- Think of your commit as expressing intent to introduce a change.

Git Clone

- Go to directory you want to save locally
- `$ git clone [url]`
- Example: `$ git clone https://github.com/conventional-commits/conventionalcommits.org.git`

Github Pages

- Updating master 
    - `$ git add .` 
    - `$ git status // to see what changes are going to be committed`
    - `$ git commit -m "Commit message"`
    - `$ git push origin master`

- If you want to create a new github-pages branch
    - `$ git checkout -b gh-pages`
    - `$ git checkout master // return to the master branch`

- If you want to update an existing github-pages branch
    - `$ git checkout gh-pages // go to the gh-pages branch`
    - `$ git rebase master // bring gh-pages up to date with master`
    - `$ git push origin -f gh-pages // commit the changes`
    - `$ git checkout master // return to the master branch`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment