How to create a pull request against branch on master

1 Comment

Say someone has created a branch for you off of master, and they want to create Pull Requests (PRs) against it. Here’s how you do it.

Get on your fork (make sure sync’d and clean) and then do

git fetch remote branch
git checkout branch

So for example

git fetch upstream imessage
git checkout imessage

Screen Shot 2017-03-20 at 2.56.48 PM.png

This grabs the upstream branch, pulls it local, and then when you checkout a branch of the same name, it automatically sets it to the upstream branch you just checked out.

Now you can create a new branch off this one, do your work, and merge it back via GHE.

git checkout -b foo`

You are now ready to work

Screen Shot 2017-03-20 at 2.58.33 PM.png

Permission denied (publickey)

Leave a comment

If you suddenly see this it’s because your the keys you use for ssh are either gone or not know to ssh. If you have them, but they just aren’t registered:

$ ssh-add -l (The agent has no identities.)
$ cd ~/.ssh (to see your keys)
$ ssh-add ~/.ssh/id_rsa (or whatever your key is called)

Also, make sure macOS (10.12+) uses your SSH key’s passphrase from the Keychain automatically

$ chmod 600 ~/.ssh/config # temporarily grant write access to the config
$ echo "Host *\n  UseKeychain yes\n  AddKeysToAgent yes" >> ~/.ssh/config
$ chmod 400 ~/.ssh/config

http://stackoverflow.com/questions/26505980/github-permission-denied-ssh-add-agent-has-no-identities

How to git rebase and squash commits

Leave a comment

Find the SHA of the commit you want squash to

Screen Shot 2017-03-02 at 9.23.34 AM.png

If we want to squash all our work down to Story X, we need to go one beyond and grab the SHA from the one after the one we want to squash down to.

Screen Shot 2017-03-02 at 9.24.44 AM.png

Cntl-v enter visual mode
Select text
c – to delete
Type what you want to appear
Press ‘Esc’ x2
Add a ‘p’ to top commit (reverse order)
Save (:wq)

Screen Shot 2017-03-02 at 9.28.19 AM.png

Screen Shot 2017-03-02 at 9.29.07 AM.png

Screen Shot 2017-03-02 at 9.29.27 AM.png

Then voila! Du ar klar! Force push in.

git push --force -n

And push back to your master

git checkout <master>
git merge <branch>

If you make a mistake

git rebase --abort

If you want to change a commit message

git commit --amend

Two squash two commits together:

git rebase --interactive HEAD~2

Dont reorder. Just take as is and change commit message when done.

How to add a git remote to a heroku app

3 Comments

There are two concepts at play when adding a user friendly heroku name to a git repos.

There is the remote (git) and the app (heroku).

git remote

Git remotes are just aliases for git repositories. You can see what alias are currently setup for your git repos by typing:

> git remote -v

heroku git@heroku.com:.git (fetch)
heroku git@heroku.com:.git (push)
origin git@github.com:/.git (fetch)
origin git@github.com:/.git (push)

origin and heroku are the remotes – and their corresponding git repos.

origin is my git hub repos.
heroku is my remote name for my heroku git repos.

When I type:

> git push heroku

It pushes my code to the heroku git repos using the ‘heroku’ git remote name.

heroku apps

When you create an instance of your code base on Heroku, it gives your app a name. You can see your app names by typing:

> heroku apps

=== My Apps
fathomless-dusk-xxx
secret-waters-xxxx

And you can get more info (like it’s git url) by typing:

> heroku info -a secret-waters-xxxx

=== secret-waters-7537
Addons: heroku-postgresql:dev
Git URL: git@heroku.com:secret-waters-xxxx.git
Owner Email: user@example.com
Region: us
Repo Size: 7M
Slug Size: 33M
Stack: cedar
Tier: Legacy
Web URL: http://secret-waters-xxxx.herokuapp.com/

What we want to do is tie these things together.

Tying a remote to an app

Say I created a staging environment, and I want to replace the heroku generated name it gave me (like secret-water) with a nicer name like ‘staging’. Here is how I would do it.

> git remote add staging git@heroku.com:secret-waters-xxxx.git

Now when I list my apps I should see staging there:

> git remote -v


staging git@heroku.com:secret-waters-xxxx.git (fetch)
staging git@heroku.com:secret-waters-xxxx.git (push)

And I should be able to push to my staging environment with this:

> git push staging

If you make a mistake you can remove a remote with

> git remote rm staging

For more examples of these and other commands feel free to checkout my heroku cheat sheet:

https://agilewarrior.wordpress.com/cheat-sheets/heroku-deploy/

How to change heroku git remote

4 Comments

If case you ever need to map your git remote back to an existing url do this:

> git remote -v

heroku git@heroku.com:protected-reef-4420.git (fetch)
heroku git@heroku.com:protected-reef-4420.git (push)
origin git@github.com:rasmus4200/agilenutshell.git (fetch)
origin git@github.com:rasmus4200/agilenutshell.git (push)

Right now heroku is pointed at protected-reef. But I want it to point to:

hidden-ridge-8790.herokuapp.com

To do that is use this command:

> git remote add heroku git@heroku.com:hidden-ridge-8790.git

> git remote -v
heroku git@heroku.com:hidden-ridge-8790.git (fetch)
heroku git@heroku.com:hidden-ridge-8790.git (push)
origin git@github.com:rasmus4200/agilenutshell.git (fetch)
origin git@github.com:rasmus4200/agilenutshell.git (push)

Done

http://git-scm.com/book/ch2-5.html

Update: If you don’t have your heroku remote created, do this:

> heroku create
> git remote set-url heroku git@heroku.com:hidden-ridge-8790.git

How to revert to an earlier version in git

1 Comment

$ git log
$ git git reset --hard SHA1_HASH
$ git push --force

Links that help:
http://stackoverflow.com/questions/373812/rollback-file-to-much-earlier-version

Git workflow

4 Comments

I’ve just started working with a team on git and I wanted a visual of what was going on every time I made a change and needed to checkin some code.

Abandon branch
$ git branch -D topic-branch

How to create a remote branch and have your friend get it

Here’s a graphic showing one way of creating a remote branch, checking it in locally, pushing it to the remote server, and then having your friend pick it up.

Pull requests

Here Mary developers a new feature locally, then pushes it to here remote branch for others to see.
She then issues a pull request allowing others to view.

git-pull-request

https://www.atlassian.com/git/tutorials/making-a-pull-request/where-to-go

Older Entries

%d bloggers like this: