Recently I’ve started to use Git 🙂 after years of SVN / TFS.
Quick tip how to set up remote repository linked with standalone local repository on your dev machine linked with your source code. As on above picture.
Why such setup ?
- It’s very convenient (for me).
- I can have all my local repositories in one local folder for all my projects.
- so it’s easy to back up all my source code at once
- and I can work offline with benefits of having code under source control (ex.: need to reverse after failed heavy refactoring – happens sometimes).
- and I can do a lot of small commits which don’t have ‘business’ value but are important for code base maintenance
- and I’m committing (pushing) to remote (official) repository (ex: GitHub or company) only finished pieces of code. (business increments).
Most simple set up procedure I can imagine:
- if you don’t have remote repository with initial/legacy code – create it by committing initially to remote repo (ex to GitHub) from your IDE or whatever how. Very easy.
- clone remote repository:
git clone --bare [remote repo url] [local repo folder path]
–bare is important.
- clone your local repository from (2) into your desired source code location.
If you created your initial project structure in (1) – delete it.
git clone [local repo path] [src code path]
Done 🙂 .
After completing above your local repo will have origin alias set to remote repository
and your source code will have origin alias set to local repository.
You commit & push your source code from your IDE into local repo.
When you are ready -> push your local repo into remote (offical) repository with :
git push origin master
or after first push just:
Git is very pleasant to work with (even with command line) after headaches with ‘visual’ TFS. It’s incredible how Microsoft still can do simple things in very bad manner.