Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Github Notes
- Notes for some of the common but complicated things I do in git.
- All in one place so that I can copy and paste them!
- ## Commit Triangle
- When setting up a new local repo follow these steps to create a triangle that
- makes pull requests and other 'GitHub' specfic tasks easier to handle.
- ```bash
- # This is the main repo such as git@github.com:OpenLiberty/open-liberty.git
- git clone [repo]
- ```
- In GitHub fork the repo you want to work on
- ```bash
- # forked-repo is YOUR fork such as git@github.com:KyleAure/open-liberty.git
- git remote add my_fork [forked-repo]
- # Set git to PUSH to your fork
- git config remote.pushdefault my_fork
- git config push.default simple
- # Ensure that you now have origin and my_fork set up
- # my_fork git@github.com:KyleAure/open-liberty.git (fetch)
- # my_fork git@github.com:KyleAure/open-liberty.git (push)
- # origin git@github.com:OpenLiberty/open-liberty.git (fetch)
- # origin git@github.com:OpenLiberty/open-liberty.git (push)
- git remote -v
- # Checkout master branch locally
- git checkout -b master origin/master
- # Get any updates and ensure you are up to date
- git pull
- git push
- ```
- ## Create a New Branch
- Used for creating a new branch with special settings if desired
- ```bash
- # Switch to master or integration branch if you are not already there.
- git checkout [master]
- # Make sure master is up to date with origin
- git pull
- # Checkout a new branch.
- # Existing-branch is optional if you want to branch off of something other than master
- git checkout -b {issue-num}[branch-name] {existing-branch}
- ```
- ## Amend Commit
- Commands to amend a commit when the changes are so small that they do not
- deserve their own commit. Also useful when making review changes so it
- looks like you got it correct the first time :D.
- ```bash
- # Add files like usual by replacing file-name with the file you want to add
- # Optionally just use -u for all tracked files or . for all files.
- git add [file-name] {-u} {.}
- # Commit your added files an an amend
- git commit --amend
- # Push amendments to origin
- # Optional -f if rewritting history
- git push {-f}
- # Check that you status is "up-to-date"
- git status
- ```
- ## Logging changes
- Useful for seeing what is happening with your repo and where your current branch/commit lies
- ```bash
- # For a tree view of where your local changes lie with origin
- git log --all --graph --decorate --oneline --simplify-by-decoration
- # For seeing commits made to origin
- # Optionally you can add how many days you want to go back
- git log origin/master --author=kyleaure {--since=10days}
- ```
- ## Rewritting History
- Useful for situations where you want to combine local commits into one when pushed to origin
- ```bash
- # Get the latest changes to origin
- git fetch
- ```
- Now we are goinng to use an interactive rebase. Rebase rewinds your local
- commits, moves your brach up to where master is now. Then attempts to
- re-play your commits on top. The {-i} tag makes this interactive so that before
- the re-play you can make changes to your commits.
- ```bash
- git rebase origin/{master} -i
- ```
- The interactive interface looks like this:
- ```
- pick xxxx
- pick xxxx
- pick xxxx
- # Rebase e227d91..7268d61 onto e227d91 (1 command)
- #
- # Commands:
- # p, pick = use commit
- # r, reword = use commit, but edit the commit message
- # e, edit = use commit, but stop for amending
- # s, squash = use commit, but meld into previous commit
- # f, fixup = like "squash", but discard this commit's log message
- # x, exec = run command (the rest of the line) using shell
- # d, drop = remove commit
- #
- # These lines can be re-ordered; they are executed from top to bottom.
- #
- # If you remove a line here THAT COMMIT WILL BE LOST.
- #
- # However, if you remove everything, the rebase will be aborted.
- #
- # Note that empty commits are commented out
- ```
- This will allow you to rewrite history by squashing, editing commit messages, etc.
- Once you have chosen how you want to edit history press `esc` and then type `:wq`
- At this point if there are merge conflics (which is always a posibility when rebasing)
- you will need to resolve those. After the rebase is finished:
- ```bash
- # Attempt a regular push first. Since we are rewriting history --force will most like be necessary.
- git push {-f}
- ```
Add Comment
Please, Sign In to add comment