0 - Add new Git repo to new GitHub repo¶ ↑
$ git init $ git add --all $ git commit
Create 'New' repo from github.com/doughazell?tab=repositories (in this case 'qc-ajax')
$ git remote add origin https://github.com/doughazell/qc-ajax.git $ git remote -v $ git push -u origin master
1 - Hot fix¶ ↑
a) Clone the 'develop' branch of 'mipi' as 'hotfix'.
$ git clone -b develop https://github.com/paullong/mipi.git hotfix;
b) Create and checkout the new hotfix branch.
$ git checkout -b hotfix-20130810;
c) Make changes.
$ git commit -a;
d) Switch to branch 'develop'.
$ git checkout develop;
e) Merge the new hotfix branch (without any 'fast-forward' issues).
$ git merge --no-ff hotfix-20130810;
f) Delete the new hotfix branch.
$ git branch -d hotfix-20130810;
g) Push the 'develop' branch merged with the hotfix up to GitHub.
$ git push origin develop;
h) Create a pull request from 'develop'.
i) Accept pull request from 'master';
EY - redeploy!
2 - Reverting file to previous commit¶ ↑
$ git status; $ git checkout -- <file>; or for all files: $ git checkout -- *;
Restore file deleted in previous commit:
$ git checkout <commit prior to delete> -- <filename>;
eg “$ git checkout 5a16b0bec533aabf4b2063f0ef6b73970735f83a – order_populator_spec.rb”
2a - Revert to previous commit¶ ↑
$ git reset --hard <sha1-commit-id>
2b - Revert to previous tag¶ ↑
$ git reset --hard <tag-name>
2c - Revert to HEAD of remote origin¶ ↑
$ git reset --hard origin/master
2y - Find diff of file on branch from master¶ ↑
$ cd `brew --repository` ; git diff origin/master Library/Homebrew/brew.sh
2y' - Revert file on branch to master HEAD¶ ↑
$ cd `brew --repository` ; git checkout origin/master Library/Homebrew/brew.sh
2z - Find diff of file from HEAD¶ ↑
$ cd `brew --repository`; git diff HEAD Library/Homebrew/os/mac/xcode.rb
3 - Adding new Rails app as branch to existing GitHub repo¶ ↑
$ cd [new app] ; git init; $ git add --all; $ git commit; $ git remote add origin https://github.com/doughazell/spreeBSC.git; $ git checkout -b 2-1-stable; Switched to a new branch '2-1-stable' $ git push origin 2-1-stable; To https://github.com/doughazell/spreeBSC.git * [new branch] 2-1-stable -> 2-1-stable $ git remote show origin; * remote origin Fetch URL: https://github.com/doughazell/spreeBSC.git Push URL: https://github.com/doughazell/spreeBSC.git HEAD branch: master Remote branches: 2-1-stable tracked develop new (next fetch will store in remotes/origin) doc_dev new (next fetch will store in remotes/origin) master new (next fetch will store in remotes/origin) rest_complete new (next fetch will store in remotes/origin) Local refs configured for 'git push': 2-1-stable pushes to 2-1-stable (up to date) master pushes to master (local out of date)
4 - Change the GitHub 'master' branch to the unrelated branch (created in step 3)¶ ↑
$ cd src; git clone https://github.com/doughazell/spreeBSC.git spreeBSC-master;
Firstly rename orig 'master'.
$ git branch -m master master-2-0-4; $ git push origin master-2-0-4; To https://github.com/doughazell/spreeBSC.git * [new branch] master-2-0-4 -> master-2-0-4
GitHub:Settings:Default Branch = “2-1-stable”
$ git clone https://github.com/doughazell/spreeBSC.git spreeBSC-master; $ git status; # On branch 2-1-stable $ git push origin :master; - [deleted] master
Now rename '2-1-stable' to 'master' (BUT don't delete orig '2-1-stable' since that's our new 'dev' branch).
$ git branch -m 2-1-stable master; $ git push origin master; * [new branch] master -> master
Rename + Delete old 'develop' branch to prevent any future misunderstandings.
$ git checkout develop; $ git branch -m develop develop-2-0-4; $ git push origin develop-2-0-4; * [new branch] develop-2-0-4 -> develop-2-0-4 $ git push origin :develop; - [deleted] develop
Now reset the GitHub repo…
GitHub:Settings:Default Branch = “master”
5 - Pull in contents of separate branch¶ ↑
Default of “git pull” = “git fetch” + “git merge FETCH_HEAD”
On branch '2-1-stable':
$ git pull origin doc_dev; $ git push;
6 - Remove a Git tracked file but NOT DELETE IT¶ ↑
$ git rm --cached <file>; $ git rm -r --cached <directory>;
7 - Push existing Git repo to new GitHub repo¶ ↑
-
Copy repo directory.
-
Create new GitHub repo.
$ cd ~/src/spree-dynamicTRANSFER ; git remote remove origin; $ git remote add origin https://github.com/doughazell/spree-dynamic.git; $ git push -u origin master; $ git remote show origin;
Push the current branch to the remote ref matching master in the origin repository.
This form is convenient to push the current branch to the master without thinking about its local name.
$ git push origin HEAD:master;
If actually wanted to push the current branch to a matching branch in the origin repo (rather than master) then…
$ git push origin [current branch name]; $ git checkout master; $ git push -f; Need to "force" since the master of the origin repo now contains the contents of the new branch
$ cd ~/src ; git clone github.com/doughazell/spree-dynamic.git;
8 - Creating a tag¶ ↑
$ git tag -a vResultsTable; $ git push --tags;
9 - Switch to remote branch without detaching HEAD¶ ↑
Need to track a remote branch by also creating a local branch (since git is LOCAL CENTRIC)
$ git clone https://github.com/doughazell/spree-dynamic.git $ cd spree-dynamic $ git checkout -b spree-3-0 origin/spree-3-0