Git -- 创建一个远程git仓库和做初始化"push"

来源:互联网 发布:淘宝静物拍照 编辑:程序博客网 时间:2024/04/25 15:08

Origin: http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/

There is loads of documentation and posts on Git out there so thisis more of a note to self as I keep forgetting the steps to setting upa remote repository and doing an initial ‘push’.

So, firstly setup the remote repository:

ssh git@example.commkdir my_project.gitcd my_project.gitgit init --baregit-update-server-info # If planning to serve via HTTPexit


On local machine:

cd my_projectgit initgit add *git commit -m "My initial commit message"git remote add origin git@example.com:my_project.gitgit push origin master


Done!

Team members can now clone and track the remote repository using the following:

git clone git@example.com:my_project.gitcd my_projectgit-track origin

Note: the ‘git-track’ command is a bash function we use to savemanually editing the .git/config file (add the following to your~/.bash_profile fileas outlined by darkliquid):

function parse_git_branch {  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'}function git-track {  CURRENT_BRANCH=$(parse_git_branch)  git-config branch.$CURRENT_BRANCH.remote $1  git-config branch.$CURRENT_BRANCH.merge refs/heads/$CURRENT_BRANCH}


h4. Bonus

To have your terminal prompt display what branch you are currently on in green, add the following to your ~/.bash_profile:

function parse_git_branch_and_add_brackets {  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ \[\1\]/'}PS1="\h:\W \u\[\033[0;32m\]\$(parse_git_branch_and_add_brackets) \[\033[0m\]\$ "


---------------------------


    git config --global user.name "Your Name"
    git config --global user.email you@example.com


原创粉丝点击