Git is a distributed version control system, widely used for software developing, can work locally or remotely. In a joint project, people usually use a git server for team cooperation so that the members can synchronize the source and logs remotely.
The most popular git server might be github, free and well-developed; however, you need to pay for the private repositories.
Bitcket is another solution for those newbies like me to try git. The private repositories are free of charge, although they can be only accessed by 5 members at most, that should be enough for a small project :)
How it works?
- Let your local directory be a git directory
- Make ssh connection between this directory to a remote one on bitbucket
- Synchronize the sources between the remote and local repositories on different clients
Setup
Install git on your client
For OSX
http://spencerimp.blogspot.tw/2012/02/git-git-on-your-mac.html
For Windows
http://spencermurmur.blogspot.tw/2013/07/git-quick-tutorial-for-git-on-windows.html
Register an account and create a repository, assuming
account: spencerimp
repository: icelandictionary
local dir: /home/spencer/iceland (yes, both of the names can be different to the remote)
Add your ssh key to the bitbucket so that you do not need to enter the password every time
ssh-keygen
Use default file (/home/spencer/.ssh/id_rsa)Enter your passphrase
Copy your content of public key (~/.ssh/id_rsa.pub)
cat ~/.ssh/id_rsa.pub
Paste the key to your bitbucket account (Manage account -> SSH keys -> Add SSH key)Edit your ~/.ssh/config
~/.ssh/config
Host bitbucket.org IdentityFile ~/.ssh/id_rsa
Note: There is a space before IdentityFileNote2: If you encounter problem locate the ~/.ssh directory with your GUI, try it via the following command:
vim ~/.ssh/config
press i
type or paste the text
press esc, then press :wq and enter
If you are using Linux, add the following into ~/.bashrc (of course, based on what shell you are using)
.bashrc
# For ssh connection to bitbucket
SSH_ENV=$HOME/.ssh/environment
# start the ssh-agent
function start_agent {
echo "Initializing new SSH agent..."
# spawn ssh-agent
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > ${SSH_ENV}
echo succeeded
chmod 600 ${SSH_ENV}
. ${SSH_ENV} > /dev/null
/usr/bin/ssh-add
}
if [ -f "${SSH_ENV}" ]; then
. ${SSH_ENV} > /dev/null
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_agent;
}
else
start_agent;
fi
##
Simple case
Initialize the local directory
git init
Add the remote repository to your project(the origin is a alias for the remote repository, you can also change it)
git remote add origin git@bitbucket.org:spencerimp/icelandictionary.git
Assign the sources to be synchronized (in this case, all of them)
git add .
if you want to remove (unmonitor) some sources
git rm unwanted_file_path
Untrack a directory
git rm -r --cached your_directory
Log the change of all your (monitored) files with a message
git commit -am 'Eyjan mín!!'
Upload (the master branch) to the remote (origin) repository
git push origin master
Update/Synchronize the local (master) branch with remote (origin) repository
git pull origin master
Remove your last commit, and you have to commit again for your new modification
git reset HEAD^
Show the tracked file list
git ls-files
Want to reset the git?
Just delete the .git directory!
Rule of thumb
Push before leave. Pull before start.
No comments:
Post a Comment