Friday 10 January 2014

Hooking up a new git repository to bitbucket

I always forget one of the steps and end up googling. That's why I'll leave this little list here to have a safety net next time I'm connecting my local repo to bitbucket.
  1. Created repository folder with a file inside inside. Something like:  /Repositories/NewRepo/helloworld.txt

  2. Open console inside of the NewRepo folder. It initiates a new git repository in the NewRepo folder:       git init

  3. We're adding the file (proposing the changes) by using:
        git add helloworld.txt
                                or
        git add *

  4. To commit the changes we use:
        git commit -m "Adding helloworld.txt"

  5. We create a repository in https://bitbucket.org/ by clicking "Create Repository" button and just filling out the form. We end up having bitbucket repository called: BitbucketLogin/reponame. Lets say our reponame is also NewRepo.

    We need to add a remote to the bitbucket repository:
    git remote add origin       https:/BitbucketLogin@bitbucket.org/BitbucketLogin/oureponame.git

    In case we're trying to commit to someone else's repo, we should use:
    git remote add origin https:/OurLogin@bitbucket.org/SomeonesLogin/soomeoneseponame.git

  6. If we made a typo in the above, we can remove the remote and add it again:
    git remote rm origin

  7. All that is left is to push the changes to bitbucket:
    git push origin master

No comments:

Post a Comment