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

git checkout master && git pull upstream master
git checkout -b my-fix
rake build:all
git commit -m "artist: Use new context menu"

Capitalize the subject line
Do not end the subject line with a period
Use the imperative mood in the subject line
Speak imperative:
“Add …”, “Change …”, “Use …”, “Refactor …”

If applied, this commit will

Forking off master

When you fork a branch, never touch the fork’s master again. Just leave it as a moment in time. Never pull or push to it.

When you need to do work, simply:
– go to your fork
– create a branch
– then pull upstream from the real master

That will give you an up-to-date local master. And you can then create your local branch and it will always be ready for work.

You can check the branch in against your fork. But never touch the fork master. Just let ghe create the PR and merge to upstream master from there.

How to rebase

git checkout master
git pull upstream master
git checkout branch
git rebase master
CONFLICT Resolve by looking for <<<<<<< HEAD
git add <conflicted file>
git rebase --continue
git rebase --skip (if there are submodules/commits you want to skip)
git push --force -n

Screen Shot 2017-01-11 at 2.45.53 PM.png

Here you can see an example of resolving a rebase conflict and being part way through.
The green files are files that have not yet been rebased.
The red file is the one you just resolved the conflict on.
While you rebase –continue the green files will be rebased too.

If you get something dirty just

rm -rf <component>
git checkout <component>

https://www.atlassian.com/git/tutorials/merging-vs-rebasing/conceptual-overview

Starting new feature

git checkout master
git pull upstream master
git push
(fork now upto date)
git checkout -b <feature>
rake clean:superclean && rake build:all

Checkout from master

> git checkout master
> git pull upstream master
> git push
> rake clean:superclean && rake build:all

Force push SHA

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

How to sync a submodule with master

cd <to submodule>
git checkout master
git fetch origin
git reset origin/master --hard

Amend

git add
git commit --amend
git push --force -n

Stash

git stash
git stash pop

Revert all changes

git clean -df
git checkout -- .

List of changes

git add -p

PR check list
1. Review your PR first in GHE before sharing with anyone else.
2. Remove all white space.
3. Review in AppCode.
4. PR should include good description, reviews, and link to story.

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

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 resolve merge conflict

#Checkout from master
git checkout master
git pull upstream master

#Merge master to your branch
git checkout um683
git merge master

# Re-push branch
git push origin um683

How to create and send someone a patch

git diff changes.patch
git apply changes.patch

How to update submodules

git submodule update --init --recursive

If you even get a dirty submodule, cd into it and undo all checkouts

git checkout .

How to reset branch

git reset --hard

How to setup global ignore

git rm --cached .DS_Store
echo .DS_Store >> ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global

http://stackoverflow.com/questions/18393498/gitignore-all-the-ds-store-files-in-every-folder-and-subfolder

How to untrack a git file (i.e. get gitignore to ignore it if already tracked)

git rm --cached filename

How to compare branch to master

git diff --name-status master dev/saveSongTour

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

tagging
https://git-scm.com/book/en/v2/Git-Basics-Tagging

git tag v1.0
git push origin master v1.0
git checkout -b version1 v1.0
git tag

# To tag a branch do the same thing but push to the remote
git tag foo
git push origin soln foo

Reset the repos

git checkout ferrari
git reset --hard origin/master
git push --force

Create new remote branchs

git branch bmw
git checkout bmw
git push --set-upstream origin bmw

Dirty files that won’t go away

git reset core
or
rm -rf components/GLUE
git checkout components/GLUE

Create new remote branch off existing one

git push origin ferrari:ferrari-nov2014
git push origin head:delorean-inter-app-protocol -u

Misc commands

git branch -vv
git branch -a

How to delete a remote branch

git push origin --delete <branch_name>

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

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

At this point you can either merge it to your own local branch

git merge player_state_notifications

Or make modifications directly on it and create pull requests and merge back.

Misc commands

git add -p (select which changes you want to add)
git log --author="xxx" --no-merges

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

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

%d bloggers like this: