Git

https://agilewarrior.wordpress.com/2016/03/17/how-to-git-rebase-and-squash-commits/

Permission denied (public key)

ssh-add ~/.ssh/id_rsa_spotify && ssh-add ~/.ssh/id_rsa_rasmus4200

Suggested workflow

Work
git checkout branch
git add .
git commit -m ""

Squash
git rebase -i SHA

Refresh
git checkout master
git pull remote/master
git checkout branch
git rebase master

Merge
git checkout master
git merge/rebase branch

At this point your changes should be at the top of master with nice clean history. Diff between merge and rebase is rebase is clearer while merge adds an extra commit showing the merge of your branch onto master.

If you have a merge conflict prefer git fetch over git pull</code. Then you can see if your master has more recent checkins before having to deal with them.

Force push SHA

git reset --hard SHA
git push --force -n
git reset upstream/master --hard

Stash

git stash
git stash pop

Revert all changes

git clean -df
git checkout -- .

How to checkout someone elses remote branch

git remote add joe git@ghe.xxx.net:joe/library.git
git fetch joe player_state_notifications
git checkout player_state_notifications

Trouble merging?

git rebase developer
BOOM Merge issue
git rebase --abort
git gc
git prune
git rebase developer
Voila

Example

Screen Shot 2017-08-01 at 5.34.06 AM.png

git remote add NYC-Infra git@ghe.xxx.net:NYC-Infra/xxx-ios.git
git fetch NYC-Infra dflm/imessage-networking
git checkout dflm/imessage-networking

or if no luck

git remote update
git checkout --track <remote>/<branch>

Note: A pull request is just a branch so to see a PR, just checkout the branch.

How to update submodules

git submodule update --init --recursive

Revert to an early version in git

$ git log
$ git reset --hard SHA1_HASH
$ git push --force -n (test push)
$ git push --force

Undo checkout individual file

$ git checkout -- filename

export repos

git checkout-index -a -f --prefix=/destination/path/
git checkout-index -a -f --prefix=/Users/jr/Downloads/temp/

Note: double -- dash on prefix

Multiple branches to find bug

git checkout -b aNewBranch1 SHA1 (test)
git checkout -b aNewBranch2 SHA2 (test)
git checkout -b aNewBranch3 SHA3 (got it!)

git branch -D aBranchToDelete
git difftool branch1 branch2

How to configure a new fork

git remote add upstream <upstream repos your originally forked>
git remote set-url --push upstream no_push
git config remote.pushdefault origin
git config --global push.default simple
git config --global pull.rebase true

How to checkout someone elses remote branch

git remote add jr git@ghe.xxx.net:jr/project.git
git fetch jr branch
git checkout branch

Misc commands

git log --author="xxx" --no-merges
git checkout --track origin/develop (setup remote track)
git push origin --delete <branch_name> (delete remote)
git log --graph --oneline

Links
https://agilewarrior.wordpress.com/2016/09/10/how-to-setup-new-ios-workflow/
http://stackoverflow.com/questions/7244321/how-to-update-a-github-forked-repository
https://agilewarrior.wordpress.com/2017/03/17/how-to-write-a-git-commit-message/
https://github.com/rowanj/gitx

Tools

GitX

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s