.git
dir1
dir2
dir3
This was fine until today, but now I'd like dir2 to live as a distinct repository.
Cloning into '/path/to/new/repository'...
done.
Rewrite dd39933a75594ac29d780de568e872fa22e1a480 (45/62) (1 seconds passed, remaining 0 predicted) Ref 'refs/heads/master' was rewritten Ref 'refs/remotes/origin/master' was rewritten WARNING: Ref 'refs/remotes/origin/master' is unchanged
Using the vague word "get" on purpose because I still don't know whether its a matter of pull, fetch, or anything else .
Initialized empty Git repository in /dev/shm/playingWithGit/repo/.git/ [master (root-commit) 2d79b06] initial commit (on master) 1 file changed, 1 insertion(+) create mode 100644 myFile Switched to a new branch 'branch1' [branch1 407687e] commit from 'branch1' 1 file changed, 1 insertion(+) Switched to branch 'master' Switched to a new branch 'branch2' [branch2 8680357] commit from 'branch2' 1 file changed, 1 insertion(+) Switched to branch 'master' Switched to a new branch 'branch3' [branch3 4188c2c] commit from 'branch3' 1 file changed, 1 insertion(+) Switched to branch 'master' branch1 branch2 branch3 * master
Switched to branch 'branch1' hello world hello from 'branch1' Switched to branch 'branch2' hello world hello from 'branch2' Switched to branch 'branch3' hello world hello from 'branch3' Switched to branch 'master' hello world
Cloning into '.'... done.
* master
hello world
Branch 'branch1' set up to track remote branch 'branch1' from 'origin'. Switched to a new branch 'branch1' hello world hello from 'branch1' Branch 'branch2' set up to track remote branch 'branch2' from 'origin'. Switched to a new branch 'branch2' hello world hello from 'branch2' Branch 'branch3' set up to track remote branch 'branch3' from 'origin'. Switched to a new branch 'branch3' hello world hello from 'branch3'
branch1
branch2
* branch3
master
Already on 'master' [master 28b51d1] another commit on 'master' 1 file changed, 1 insertion(+) Switched to branch 'branch1' [branch1 0ff4301] another commit on 'branch1' 1 file changed, 1 insertion(+) Switched to branch 'branch2' [branch2 fcab109] another commit on 'branch2' 1 file changed, 1 insertion(+) Switched to branch 'branch3' [branch3 fcf5830] another commit on 'branch3' 1 file changed, 1 insertion(+)
Switched to branch 'branch1' hello world hello from 'branch1' I made this commit on branch 'branch1' after the 'clone' Switched to branch 'branch2' hello world hello from 'branch2' I made this commit on branch 'branch2' after the 'clone' Switched to branch 'branch3' hello world hello from 'branch3' I made this commit on branch 'branch3' after the 'clone' Switched to branch 'master' hello world I made this commit on branch 'master' after the 'clone'
remote: Enumerating objects: 20, done. remote: Counting objects: 100% (20/20), done. remote: Compressing objects: 100% (8/8), done. remote: Total 12 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (12/12), done. From /run/shm/playingWithGit/repo 4188c2c..fcf5830 branch3 -> origin/branch3 407687e..0ff4301 branch1 -> origin/branch1 8680357..fcab109 branch2 -> origin/branch2 2d79b06..28b51d1 master -> origin/master
branch1
branch2
* branch3
master
Switched to branch 'branch1' Your branch is behind 'origin/branch1' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) thank you, Git hello world hello from 'branch1' Switched to branch 'branch2' Your branch is behind 'origin/branch2' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) hello world hello from 'branch2' Switched to branch 'branch3' Your branch is behind 'origin/branch3' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) hello world hello from 'branch3' Switched to branch 'master' Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) hello world
branch1 branch2 branch3 * master Updating 5784923..5ccb801 Fast-forward myFile | 1 + 1 file changed, 1 insertion(+) Current branch master is up to date. hello world I made this commit on branch 'master' after the 'clone'
Switched to branch 'branch1' Your branch is behind 'origin/branch1' by 1 commit, and can be fast-forwarded. As seen above (use "git pull" to update your local branch) Ok, I'll do this !
Updating b5e84db..6f16d51 Fast-forward myFile | 1 + 1 file changed, 1 insertion(+) Current branch branch1 is up to date.
hello world hello from 'branch1' I made this commit on branch 'branch1' after the 'clone'
Already on 'branch1' Your branch is up to date with 'origin/branch1'. Already up to date. Current branch branch1 is up to date. hello world hello from 'branch1' I made this commit on branch 'branch1' after the 'clone' Switched to branch 'branch2' Your branch is behind 'origin/branch2' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) Updating 1e4eef9..56d7474 Fast-forward myFile | 1 + 1 file changed, 1 insertion(+) Current branch branch2 is up to date. hello world hello from 'branch2' I made this commit on branch 'branch2' after the 'clone' Switched to branch 'branch3' Your branch is behind 'origin/branch3' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) Updating 545c032..ab21a4f Fast-forward myFile | 1 + 1 file changed, 1 insertion(+) Current branch branch3 is up to date. hello world hello from 'branch3' I made this commit on branch 'branch3' after the 'clone' Switched to branch 'master' Your branch is up to date with 'origin/master'. Already up to date. Current branch master is up to date. hello world I made this commit on branch 'master' after the 'clone'
git rev-parse --show-toplevel
On branch master nothing to commit (use -u to show untracked files)I expected something like :
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
* master 6f3d70e (a very interesting commit message)should be :
* master 35ca599 [origin/master] (another highly interesting commit message)
fatal: No upstream configured for branch 'master'should be :
refs/remotes/origin/master
This is because the master local branch has no upstream origin/master remote branch to be compared to.
The presence or absence of an upstream setting mainly affects whether git status can tell you if you are ahead or behind, and whether git merge and git rebase can do their job with no additional parameters. So it's basically just a convenience setting.
* master 6f3d70e [origin/master: ahead 7] (a very interesting commit message)
refs/remotes/origin/master
On branch master Your branch is ahead of 'origin/master' by 7 commits.
git gc --aggressive --prune
Resulted in a ~10% volume decrease.
This is dirty1000 and is actually not recommended.
Counting objects: 6, done. Delta compression using up to 2 threads. Compressing objects: 100% (6/6), done. Writing objects: 100% (6/6), 697 bytes | 0 bytes/s, done. Total 6 (delta 4), reused 0 (delta 0) remote: error: refusing to update checked out branch: refs/heads/master remote: error: By default, updating the current branch in a non-bare repository the error remote: error: is denied, because it will make the index and work tree inconsistent remote: error: with what you pushed, and will require 'git reset --hard' to match remote: error: the work tree to HEAD. remote: error: remote: error: You can set 'receive.denyCurrentBranch' configuration variable to remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into the solution remote: error: its current branch; however, this is not recommended unless you remote: error: arranged to update its work tree to match what you pushed in some remote: error: other way. remote: error: remote: error: To squelch this message and still keep the default behavior, set a workaround remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. To gitServer:/path/to/repository ! [remote rejected] master -> master (branch is currently checked out) error: failed to push some refs to 'stuart@gitServer:/path/to/repository'
(nothing but UNIX FAILURE
exit code)
This directive is currently unset.
ignore
With Git 2.3.0+, it is possible to safely push to a non-bare repository with :
Counting objects: 6, done. Delta compression using up to 2 threads. Compressing objects: 100% (6/6), done. Writing objects: 100% (6/6), 697 bytes | 0 bytes/s, done. Total 6 (delta 4), reused 0 (delta 0) To gitServer:/path/to/repository f5c8ce7..629a87e master -> master
Keep in mind that any private information that has been committed to a public repository MUST BE CONSIDERED AS COMPROMISED. So, clean up your mess, but forget about your passwords, keys, ... and generate new ones !!!
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch ./test' --prune-empty --tag-name-filter cat -- --all
Rewrite de1291f7f10da919f611358539e3d2e0acfd632f (1/9)rm 'test' Rewrite 023a969f60328055b6cab2e1a82e307760b7a308 (2/9)rm 'test' Rewrite aaffedfe16c297d02c2fee5eb72b740c91cae942 (3/9)rm 'test' Rewrite 8a766a9226e360ba0f147ae9c890cec200f958d7 (4/9)rm 'test' Rewrite 1f9bd643aa3495f46ca9470c021a56f8a0765c62 (5/9)rm 'test' Rewrite 2e22a397f2283f398038d9a44f451914c0a58f68 (6/9)rm 'test' Rewrite 15f247b46d558b057ccead7f7980c7f24b58879c (7/9)rm 'test' Rewrite e54ff82df52d8e7d02749b17e4fac4aa9386122e (8/9)rm 'test' Rewrite 5bbcaf42adac870f13295b2bbe2673807bf1e059 (9/9)rm 'test' Ref 'refs/heads/master' was rewritten Ref 'refs/remotes/origin/master' was rewritten
http://stackoverflow.com/questions/1338728/delete-commits-from-a-branch-in-git
git reset --hard commitId WARNING, this deletes all commits from the current point back to commitId. Use with care !!!
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin git reflog expire --expire=now --all git gc --prune=now
==========================================8<========================================================= IN CASE OF SENSITIVE DATA PUSHED TO GITHUB : SOLUTION 1 : untrack sensitive file from local git (see above) delete sensitive file from local git history http://help.github.com/remove-sensitive-data/ git filter-branch --index-filter 'git rm --cached --ignore-unmatch hosts.csv' --prune-empty -- --all ==> Doesn't seem to work on directory containing uncommitted modifications. If error message : Cannot create a new backup. A previous backup already exists in refs/original/ ==> git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch output/hosts.cfg' --prune-empty -- --all commit to local repo commit to GitHub <to be checked> ==> sensitive file still visible in history [Grok mode] delete GitHub repo + recreate it (within web UI) + RE-SETUP above then push local repo to GitHub : git push -u origin master --force [Normal mode] force push local repo to GitHub : git push -u origin master --force </to be checked>
Before starting this procedure, make sure there are no uncommitted changes on both repositories. commit or stash them accordingly.
Stuff below could be obsolete / wrong git clone https://github.com/sni/Thruk.git git remote add --track master upstream git://github.com/Httqm/Thruk.git git branch newFeature git checkout newFeature [do some code modifications, commit] git push upstream newFeature (?)
checkout is the SVN command to get a local copy of a project from its main repository (when joining a team, for instance).
Git also has a checkout command, but it has a different meaning.
The Git equivalent of SVN checkout is git clone.