Showing posts with label Git. Show all posts
Showing posts with label Git. Show all posts

Friday, September 7, 2012

Git re-initialize fix after corruption

Today, a project directory was somehow corrupted and cannot add new file nor commit modified files to the local repository. 
With error like these:

$ git add .
error: insufficient permission for adding an object to repository database .git/objects

error: clickthecity.rb: failed to insert into database
error: unable to index file clickthecity.rb
fatal: updating files failed


It's found that some directories under .git/objects were owned by root.  Maybe some commits were done under the root access.
After a few tries in vein, I do just re-initialize the local git repository.

$ sudo rm -rf .git
$ git init
$ git add .
$ git remote add origin [your_server]:[dir]
$ git commit -a -m "..."
$ git pull origin master


And do some code merging.

$ git push origin master

Done.

Thursday, August 9, 2012

Setup Git server on Linux

  • Setup ssh login
    • ssh [your_name]@[server_name] mkdir .ssh
    • scp ~/.ssh/id_rsa.pub [your_name]@[server_name]:.ssh/authorized_keys
  • Install Git:
    • ssh [server_name]
    • sudo apt-get update
    • sudo apt-get install git-core
  • If a shared repository is need, create a git user:
    • sudo adduser git
    • ... cont on setup ssh login.
  • Add repository
    • Login as your_name or git
    • mkdir myrepo.git
    • cd myrepo.git
    • git --bare init
  • Setup development machine 
    • git remote add origin [server_name]:myrepo.git
    • git push origin master
  • Done

Monday, July 9, 2012

Git daily usage cheat sheet


TaskCommand
Initialize a new git repository
git init
View local branchesgit branch
Create new local branchgit branch [new_branch_name]
Delete local branchgit branch -d [branch_name]
Switch to a branchgit checkout [branch_name]
Add files to gitgit add .
Undo all current changes.git checkout .
Commit changesgit commit -a -m "Log message"
Show git logsgit log
Push local to remotegit push origin [branch_name]
Pull from remotegit pull origin [branch_name]
Merge branchgit merge [from_branch]
Show diffgit diff
Show all branchesgit branch -a
Fix a tagged release
git checkout -b [tag_name]_fixes [tag_name]
OR (for getting a remote branch)
git checkout -b [new_local_branch] origin/[remote_branch]

e.g.

git checkout -b myfeature origin/myfeature
Create a new taggit tag [tag_name]
Push tags to remotegit push --tags
Overwrite existing taggit tag -f [tag_name]
Delete tag
git tag -d 12345
git push origin :refs/tags/12345
Merge individual commitsgit cherry-pick [commit_hash]
Stashing
git stash
git stash apply
git stash list
Create an empty repositorygit --bare init
Adding a remote repository
git remote add origin [server_name]:[directory_name]

Checkout a single file on another branch:
$ git checkout branch_name file_full_path

More on: http://gitref.org/index.html

Tuesday, February 28, 2012

Github - Source control


Free public repositories, collaborator management, issue tracking, wikis, downloads, code review, graphs and much more…

https://github.com/