Skip to content

Instantly share code, notes, and snippets.

@GirlBossRush
Last active August 29, 2015 14:01
Show Gist options
  • Save GirlBossRush/6dc3ed085c790a4b2b76 to your computer and use it in GitHub Desktop.
Save GirlBossRush/6dc3ed085c790a4b2b76 to your computer and use it in GitHub Desktop.

Git tips.

# Fetch branch updates from remote, and merge them into the respective local copy.
➜  iknow git:(stable) git pull

# Fetch all branch updates, but do nothing after.
➜  iknow git:(stable) git fetch

# Create and check out a branch from your current checked out branch (stable, some-feature-branch-#123, etc) 
➜  iknow git:(stable) git pull ### The branch may have updates that your local copy does not have...
➜  iknow git:(stable) git checkout -b header-redesign-#345

# Publish your local branch to the remote (github). Shorthand for git push origin HEAD:header-redesign-#345
➜  iknow git:(header-redesign-#345) git shove 

An example of branching an existing feature branch, then merging back in.

➜  iknow git:(header-redesign-#345) git pull
➜  iknow git:(header-redesign-#345) git checkout -b header-avatar-#345 ### Create...
➜  iknow git:(header-redesign-#345) git shove #### Publish branch...
➜  iknow git:(header-avatar-#345) ....staged files with gitg... 
➜  iknow git:(header-avatar-#345) git pull ### Fetch header-avatar-#345 remote changes, if any, and merge them into your local copy.
➜  iknow git:(header-avatar-#345) git push ### Push your local commits to the remote. This will be rejected if new commits are not pulled first.
➜  iknow git:(header-avatar-#345) git checkout header-redesign-#345 ### Checkout the parent. 
# Merge sub feature branch into parent as seemingly one commit. Shorthand for git merge --no-ff -
➜  iknow git:(header-redesign-#345) git meld - ### '-' means "last branch I checked out".

Submodules: Git repositories inside git repositories.

iKnow and Smart API share a common set of models and helpers, known as smart_core. iKnow's and Smart API's Gemfile references smart_core's Gemfile too.

cd /data/
➜  git clone [email protected]:cerego/iknow.git
➜  cd /data/iknow
➜  iknow git:(stable) ls vendor/plugins/smart_core ### Does not exist!
➜  iknow git:(stable) git submodule init ### Setup submodules
➜  iknow git:(stable) git submodule update ### Essentially `git clone [email protected]:cerego/smart_core.git` in vendor/plugins/smart_core
➜  iknow git:(stable) ls vendor/plugins/smart_core
Gemfile README app config.ru  init.rb log  script  test.......etc

Every branch has a smart_core pointer that references what commit is checked out for smart_core.

Checkout smart_core pointer. Shorthand for git submodule update

➜  iknow git:(stable) ✗ git sub
➜  iknow git:(stable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment