пʼятниця, 7 вересня 2012 р.

Git pocket tutorial

My first post about git repository.

At the beginning we must initialize out repo. Let's say it have tempo name. For now we guess that repo was created on git server and we only must create a local copy on our development machine. First of all we must install git client. Further i will talk about linux console version of client. On the next step we must initialize our local repo:
  1. git init
  2. git add <file1> <file2> ...
  3. git commit -m "init commit"
  4. git remote add origin git@remoterepo.host.addr:username/path/to/tempo.git
  5. git push -u origin master
General format for git remote add(4) is:
git remote add remote_name remote_location
Also we have git clone with similar format:
git clone remote_location
You can ask, what the difference between "remote add" and "close" and i answer you:
  1. remote add - creates an entry in your git config and you can either push changes to remote repo
  2. clone - creates new repo (local copy from remote_location). It similar to this code:
git init
git remote add origin remote_location
git pull origin master
Now let's talk about work with branches. First of all you need to create one by command:
git branch
After that you can view branches:
git branch - show your local branches
git branch -a - showing all branches including remote ones
When our new branch was founded in list - we can switch to it:
git checkout <branchname>
After work on it - we can remove it
# delete local
git branch -d <branchname>
# remote
git push origin :<branchname>
We can push changes to remote branch after committing:
git push origin <branchname>:refs/heads/<branchname>
When work on branch was finished - it can pushed to master:
git checkout master
git merge <branchname> --no-ff
git push origin master - push master branch to remote repo
If you need update code from remote repo:
git remote update; - update all remote repos
git pull <remoterepo> <local>  

Немає коментарів:

Дописати коментар