Vous êtes sur la page 1sur 6

*Set up the remote repository.

* _- on the remote server:_ 1) create a directory on the remote server which will hold the .git files (does not necessarily have to contain your project files) 2) enter that directory and initialize git remote directory files with the command: git init -bare 3) create a work directory which will hold your project files (wherever is more suitable for you) 4) set the work directory creating the file post-receive in hooks directory in the git remote directory containing the following text (adjust to your paths): echo "Branch pushed! Starting to copy to work folder!" read oldrev newrev ref cd /media/nfs/repository/project.git if [ $ref = "refs/heads/master" ]; then git symbolic-ref HEAD refs/heads/master GIT_WORK_TREE=/media/nfs/repository/working-master git checkout -f echo "Files copied on remote repository to /media/nfs/repository/working-master" elif [ $ref = "refs/heads/development" ]; then git symbolic-ref HEAD refs/heads/development GIT_WORK_TREE=/media/nfs/repository/working-development git checkout -f echo "Files copied on remote repository to /media/nfs/repository/working-development" elif [ $ref = "refs/heads/release" ]; then git symbolic-ref HEAD refs/heads/release GIT_WORK_TREE=/media/nfs/repository/working-release git checkout -f echo "Files copied on remote repository to /media/nfs/repository/working-release" fi 5) make sure that the file is executable in linux you can use the command: chmod +x /path/git_directory/hooks/post-receive All the pushed files to a certain branch on the remote git repository will be now located in the specific remote work directory.

*Pulling existing project from remote repository:* If you need to pull a certain branch of the project from the remote to local repository, just follow these indications: 1) configure your local git repository git init 2) add the remote repository address; git remote add <repository_name> ssh://user@<ip_add>/path/git_remote_directory - check with any existing ones with git remote - delete any remote repository address with git remote rm <repository_name> 3) Pull the existing project and the remote branches names: git pull <repository_name> - this will download the whole project and remote branches names - you will be notified of the remote branches that were pulled and get a message about not specifying a branch..this is normal - you can check what remote branches have been pulled with git branch -r - if needed, you can check the contains of a certain remote branch before adding it with git checkout <remote_name> 4) add any remote branch to a local new branch, tracking it at the same time with:

git checkout --track -b <local name> <remote_name> _ex: git checkout --track -b master phrugle/master_ Repeat the actions for any repository or remote branch you need. To push and pull the latest changes to/from the remote repository you can use: - for all tracked branches at once git pull/push - for a certain branch only git pull/push <repository_name> <local_name>

Enter the personal info that will be used to identify every commit git config --global user.name Developer X git config --global user.email example@domain.com - enable color ui git config --global color.ui true

*Creating a new project:* - on the local machine: 1) create a work directory (this directory will contain your project files and .git files, which will be a hidden directory) 2) enter that directory (all the git commands will be run in this directory) and initialize git directory files with the command: git init 3) enter some information the will be used to identify every commit and set the optional color text ui: git config --global user.name Developer X git config --global user.email example@domain.com git config --global color.ui true

4) you will now have to make the initial commit; for this you will need to create, add and commit a file; in the initial commit there will be created the master branch, which will be used as the final production branch; any project will have to be created in the development branch, pushed to the release branch where there will be made the final minor changes and then pushed into the master branch as the final version of the project. You can either copy some files from the local computer into your local work folder, add them to the index git add -A and then commit them as your Initial import git commit -a -m Initial import or create a file yourself and do the same steps. - to remove a file can use git rm <file_name> and then add and commit the change Git is keeping a log with all the changes you make so you can always revert to any state, that you can access with: git log - or in a more friendly version git log --pretty=format:"%h - %an, %ar : %s" More about log options: [[http://git-scm.com/book/en/Git-Basics-Viewing-the-Commit-History]] More about undoing changes: [[http://git-scm.com/book/en/Git-Basics-Undoing-Things]] - you should have now a new branch called master - you can list local branches using git branch - the active branch (the one you are working on) is highlighted and marked with an * character - to create a new branch use the command: git branch <new_local_name>

- to delete a branch use: git branch <local_name> --delete

- to change between branches use the command: git checkout <branch_name> You will get a message notifying on which branch you are. ALWAYS be sure that you are working on the right branch. 5) to push them to the remote server, we have to first add its address and set the repository name: git remote add <repository_name> ssh://user@<ip_add>/path/git_remote_directory 6) set the origin and destination branch for each local branch; create the remote repositories; you must start with the master branch: git push <repository_name> +<local_branch>:refs/heads/<remote_branch> _ex: git push phrugle +master:refs/heads/master git push phrugle +development:refs/heads/development git push phrugle +release:refs/heads/release_ 7) set up tracking of the branches. - check that you have the local branches and the remote branches that you will use to track: git branch -a - to track a certain branch, use: git branch --set-upstream <local_branch> <remote_branch> _ex: git branch --set-upstream master origin/master_ - you can check that the branches are tracked using: git remote show <repository_name> Do this for all of the branches you need. 8) to get the latest changes in a certain branch you use git pull <repository_name> <branch>

!! make sure you are working on that branch !! - this which will immediately write the changes, without being able to review them. - if there will be any conflicts, you will be notified and then you can force the overwriting of your local repository with git pull <repository> <branch> -ff - or you can fetch, review and merge the changes manually as it follows: git fetch <repository> <branch> If there are any changes, you will get a similar line in the output: _ca5996e..acb5c35 master -> phrugle/master_ - check the differences between the local version and the remote version: git diff <local_branch> <remote_branch> _ex: git diff master phrugle/master_ Review the changes and merge the versions git merge <local_branch> <remote_branch> _ex: git merge master origin/master_ 9) to push the changes from a branch to another: _ex: you want to push the changes of the development branch to the release branch on local:_ 1) change the working branch to the release branch 2) to merge the braches use: git merge development 3) push the release branch changes to the remote server Official git ebook: http://git-scm.com/book

Vous aimerez peut-être aussi