There is a great deal of documentation and many posts on Git out there, so this is more of a note to self as I keep forgetting the steps needed to set up a remote repository and doing an initial “push”.
So, firstly setup the remote repository:
ssh git@example.com mkdir my_project.git cd my_project.git git init --bare git update-server-info # If planning to serve via HTTP exit |
On local machine:
cd my_project git init git add * git commit -m "My initial commit message" git remote add origin git@example.com:my_project.git git push -u origin master |
Done!
Team members can now clone and track the remote repository using the following:
git clone git@example.com:my_project.git cd my_project |
Bonus
To have your terminal prompt display what branch you are currently on in green, add the following to your ~/.bash_profile (I have my current directory displayed in cyan):
function git-branch-name { git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3 } function git-branch-prompt { local branch=`git-branch-name` if [ $branch ]; then printf " [%s]" $branch; fi } PS1="\u@\h \[\033[0;36m\]\W\[\033[0m\]\[\033[0;32m\]\$(git-branch-prompt)\[\033[0m\] \$ " |
does not work for me !
fatal: ‘me@myremote/xxx…/’ does not appear to be a git repository
fatal: The remote end hung up unexpectedly
Are you 100% that ‘me@myremote/xxx…/’ has had ‘git init –bare’ run on it.
Pingback: my git reminder
Make sure the git user and group owns the repository directory on the remote. If it doesn’t, use the chown command to make the proper changes.
Ah, you have to create the remote project first. I skipped that step thinking it would be created automatically with the first push. Of course, it took a few more dead ends to figure out how to get everything in sync again since the remote repository was created after the local one.
It’s not difficult, just a little confusing figuring it out.
It would be helpful to update the post for anyone who might make the same mistake.
Thanks for the tip!
I love this site!
Pingback: Getting Started with GIT for Designers
Thank you! This is really useful!
I receive the following error in the shell after adding the bonus function to my .bash_profile:
sed: -e expression #2, char 4: unterminated `s’ command
Pingback: Setting up GIT on a Windows computer | Diary of a Web Dev
Pingback: Git branch in prompt | jh.net