Intro to Git and Bitbucket
Before you start/join a project:
Create a Bitbucket account
Install Git (if coding locally on your desktop)
In the terminal, link your Bitbucket account with Git:
git config --global user.name "username"
git config --global user.email "bitbucket_email@email.com"
For each project you are working on:
In Bitbucket: Make your branch for the repo
Also in Bitbucket: Click clone and copy the git clone
command for the repo
Paste this command in your terminal
Before we get coding, we need to make sure that our user branch is up to date with any changes in the main branch.
git checkout main
moves to the main branch
git pull main
pulls changes in the remote repo to your local repo
git checkout user
moves to the user branch
git merge main
merges main branch into the branch we are currently in (user)
Working Directory: Where you add/edit content
Staging Area: Temporary area where we see files that were changed
Local Repo: Locally available version of the remote repo
Remote Repo: Online repo where uploaded content is stored
git add
adds copies of files you edit in the working directory to the staging area
git add --all
to add all files you have editedgit commit
saves these files to your local repo
git push
uploads whatever is in your local repo to your branch in the remote repo
Now that you’ve made your edits and updated your branch in the remote repo, we can update the main branch from our user branch.
Merge your user branch into the main branch:
git checkout main
moves to the main branch
git merge
user
merges the user branch into the branch we are currently in (main)
Be careful: merge conflicts can occur when the same lines of a file have been changed by two developers.
In Bitbucket, you can use pull requests to merge your branch into main and to prevent merge conflicts.
Getting edits from your remote branch to your local repo:
git checkout user
will make sure that you are in the correct branch
git pull
adds copies of these files to your local repo
Before you start working, you want to make sure everything is up to date:
git checkout user
moves to your branchgit pull
gets changes in your remote branchgit checkout main
moves to maingit pull
gets changes in remote maingit checkout user
moves back to your branchgit merge main
merges main into your branchgit push
updates your remote branchgit status
can be used to figure out whether your branch is up to date and which files are staged or untracked before you commitGit
: free and open source distributed version control system that tracks development in files (including code) and is often used for collaboration between developers Git Commands:
git add
: moves changes from working directory to staging area
git checkout
: navigates between branches
git clone
: copies an existing Git repo -
git commit
: takes content in the staging area and commits it to the local repo
git config
: sets configuration options for Git
git merge
: combines changes from different branches
git pull
: downloads branch from remote repo and merges it into the current branch
git push
: copies content in a local repo branch to a remote repo branch
git status
: prints information about the state of the working directory and staging area
A more complete glossary of Git commands can be found here
Branch:
line of project development used to maintain and manage individual edits for different developers and/or sections of the projectMerge Conflict:
occurs when multiple edits happen to the same line at the same time on two different versions, so Git is unable to determine which version to keepPull Request:
method of merging branches that notifies other team members and creates an interface for seeing changes and potentially resolving merge conflictsRepository:
a collection of files and versions of a projectLocal:
on your computerRemote:
stored on a server, accessible onlineStaging Area:
location where files are added before committed to the local repoWorking Directory:
a singular version of the project where you create and edit project files