Source Control with GIT and BitBucket

gitSource Control: Trust me on this – you do need it! The best tool is GIT – and it’s free  :-) Add BitBucket (or GitHub) and your code will be backed-up and accessible from everywere.

Native GIT runs from a command prompt, so store your projects in a folder close to the root, e.g. C:\dev\projectname

Beware: To use GIT you must understand GIT – get the full story in this guide, or start with this tutorial

I use GIT on my own projects, making hourly commits and daily pushes to BitBucket. If I need to branch or merge code, I use the tools in BitBucket or GIT Extensions

FIrst-time installation and configuration

  1. Download and install GIT (Installation guide)
  2. Setup GIT – apply your username and email address by using these commands:
     $ git config --global user.name "John Doe"
     $ git config --global user.email johndoe@example.com
     

    or just manually update the .gitconfig file (in your local folder, e.g. C:\Users\$USER). My file looks like this

     [user]
     name = Jakob Majkilde
     email = jakob@majkilde.dk
     [http]
     proxy = http://80.254.148.90:8080
     [core]
     autocrlf = true
     excludesfile = c:/dev/.gitignore
     

    Notice: only the [user] is mandatory – other settings are optional

  3. Add a .gitignore file to automatically exclude files that you do not want in your repository (e.g. .exe files or log files). Read the documentation for more info. I have my ignore file in my developement folder and made it global

Starting a new project

  1. Open a command prompt, goto your project folder and type GIT init (this will create a hidden sub folder called .git)

Often used commands

  • Add files: GIT add -A
  • Commit: GIT commit -m “Type a message here”
  • Status: GIT status
  • Commit log: GIT Log
    git log --graph --pretty --oneline --abbrev-commit

Push to a remote repository (e.g.BitBucket)

  • Connect: git remote add origin https://majkilde@bitbucket.org/majkilde/<project name>.git (url can be copied from your bitbucket repository)
  • Push: git push -u origin master
  • Pull: git pull origin master 

Links

One thought on “Source Control with GIT and BitBucket

  1. Pingback: Source Control i Domino med GIT/BitBucket | XPages.dk

Leave a Reply

Your email address will not be published. Required fields are marked *