Glen Mazza's Weblog

https://glenmazza.net/blog/date/20150621 Sunday June 21, 2015

Git & GitHub Notes
  1. For ease, fork the repo on GitHub and clone your fork rather than the main repo, then

    git remote add upstream git@github.com:githubaccountname/githubrepo.git
    to link to main repo.

  2. git push origin branchName -- "origin" refers to the fork (here, one's own, else can be upstream or any other created via git remote)

  3. To switch between branches locally, git checkout <branch name> (use git branch to see a list); to check out a new branch based on the one you're currently in, git checkout -b <new branch name>

  4. git fetch upstream [branch or remote branch:local branch] - update pointers to latest code, git merge afterwards (or git pull to do both) to update local code. If any automated merge failures, right-click Git->Resolve Conflicts from IntelliJ to resolve manually.

  5. To place your changes on one branch above those from another: (from your branch): git fetch as above, then

    git rebase [branch name to retrieve from]
    , then
    git push origin brname -f
    to update GitHub fork.
  6. Recovering from an accidental pull: SO #1, SO #2. Another possibility: git rebase -i HEAD~xxx to supposedly squash the commits, but I instead removed all unwanted commits from the pull. Then git rebase to bring in actual wanted branch.

  7. To pull a different branch to your local machine:

    git remote add upstream git@github.com:githubaccountname/githubrepo.git
    git fetch upstream
    git co upstream/release/branchname
    git co -b [newBranchNameHere]
    
  8. To checkout a tag.

  9. To check out a coworker's branch:

    git remote add coworkerFork https://github.com/coworkerAcct/Repo.git
    git fetch coworkerFork hisBranch:newNameForYourLocalBranch
    
  10. In GitHub pull requests, use ``` or ```json to format code (JSON)

  11. In PR reviews, use : to bring up icons.

  12. Deleting a branch:

    git branch -D branchnames...

  13. List of repos presently watching: https://github.com/watching

  14. Squashing commits:

    git log
    to find number of commits to squash,
    git rebase -i HEAD~X
    (X is number of commits). 1st page: mark all but first commit "s" for squash, 2nd page, edit common commit message. Standard editor: Ctrl-K to remove lines, Ctrl-X to save. Then
    git push origin brName -f
    to update remote.

  15. git cherry-pick to copy commits from one place to another. Applying a commit from one branch to another:

    git log to copy sha of commit you want to merge
    git fetch upstream to download all available branches
    git co -b mynewbranch
    git pull upstream {branchYouWantToAddPRTo}
    git cherry-pick { sha value} -m 1
    git push origin mynewbranch
  16. How to merge a PR against one fork into your own
  17. Wanting to create a new branch without committing changes first:
    git stash, git checkout -b newBranch, git stash pop
  18. Undoing changes:
    git checkout <branch_copying_from> -- <file_to_reset>
  19. branch rewinding - another method for combining commits when the work was not done on a separate branch.
  20. JQuery Commits and Pull Requests Guide
  21. Checking out an older git version (snapshot)
  22. Adding Git Aliases -- simplify terminal window commands
  23. Efficient way to do commits:
    git log --oneline --decorate
  24. Which release contains a commit? git fetch --all followed by git tag --contains (hash)
  25. Amending commit messages

Posted by Glen Mazza in Programming at 07:00AM Jun 21, 2015 | Comments[0]

Post a Comment:

Calendar
« July 2020
Sun Mon Tue Wed Thu Fri Sat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Today
About Me
Java Software Engineer
TightBlog maintainer, Apache CXF committer
Arlington, Virginia USA
gmazza at apache dot org
GitHub LinkedIn
Blog Search
Apache CXF/SOAP tutorial
Blog article index


Today's Blog Hits: 3379
Navigation
About Blog
Blog software: TightBlog 3.7.2
Application Server: Tomcat
Database: MySQL
Hosted on: Linode
SSL Certificate: Let's Encrypt
Installation Instructions