Server: 192.168.0.100
User on the server: git
Project: spsw
User on the client: Wayne
- On the server
- Login the git server
ssh git@192.168.0.100 - Create a directory for the project "spsw". A repository on server should be bare, and by convention, a bare repository is named with ".git" suffix.
mkdir spsw.git
cd spsw.git - Initialize a bare repository.
git init --bare
- On the Client
- Setup you personal information.
git config --global user.name "Wayne"
git config --global user.email "wayne@gmail.com" - Create a non-bare repository. There are two ways to do this.
- By cloning the source from the server. (This assumes that the server has the source code, but so far we haven't put our source to the server - the server doesn't has the source code)
- git clone git@192.168.0.100:/home/git/spsw.git
- By creating a new project and then putting to the server.
- Create a directory for the project spsw. (".git" suffix is not needed because it's a non-bare repository)
mkdir spsw
cd spsw - Initialize a non-bare repositry.
git init - Copy your source here
- Add all the files. ("git add ." is the choice for this case)
git add . # Add new and modified without deleted
git add -u # Add modified and updated without new
git add -A # git add . && git add -u - Show what you've added or changed if you want.
git diff - Commit the changes.
git commit -a -m "changes description" - Add the git server source and name it "origin"
git remote add origin git@192.168.0.100:/home/git/spsw.git - Put the source code in current branch to the server "origin" and branch "master".
git push origin master - Upate the source from the server.
git fetch # download the source to branch "origin/master"
git merge # merge "origin/master" to the current branch.
git pull # git fetch && git merge - Some useful commands operating branches
- Create a new branch
git branch new_branch - Swith to new_branch
git checkout new_branch - Delete new_branch
git branch -D new_branch - show the list of all the branches
git branch -a
git show-branch - Other useful commands
- View all you've commit
git log - Show a commit detail
git show commit_number - Give a commit a tag like a name
git tag -m "version 1.0" 1.0 commit_number
git show 1.0
- Reference
- Books
- Version Control with Git
- Pro Git
No comments:
Post a Comment