Local: this is your local environment, e.g. on your PC or Mac.
Origin: this is your remote repository, e.g. on GitHub or BitBucket.
List all local branches:
$ git branch
List all remote (in origin) branches:
$ git branch -r
Create a new local branch:
$ git branch name_of_my_new_local_branch
Checkout previously created branch:
$ git checkout name_of_my_new_local_branch
Currently, you only see your branch locally (not on BitBucket for example). To make it visible in BitBuck (aka remote or origin), you have to push it like this:
$ git push -u origin name_of_my_new_local_branch
With this command you can set the upstream branch. This is the branch from which you eventually pull/track changes. In the previous example (git push -u origin name_of_my_new_local_branch
) we set it to the newly created branch and this is usually what you want.
$ git branch -u origin/develop
If you have created (or someone else even) a new branch on BitBucket, then you can use this command to make it visible locally as well (otherwise you woulnd't see it):
$ git fetch --all
If you now enter git branch
your remotely created branch should be visible now.
List all files that were changed (usually displayed in red) or see which files were added (via git add
, see next command) (usually displayed in green):
$ git status
With this command you can add the files you want to commit:
$ git add my_changed_file1 my_changed_file2
With this command you can add all (e.g. .
means everything in that current directoy/branch) changes you made:
$ git add .
With this command you commit your previously added changes. You should add a meaningful commit message:
$ git commit -m "my commit message"
With this command you can push your local changes that you previously commited to your remote (on origin, i.e. BitBucket) branch:
$ git push origin name_of_my_new_local_branch
When you're not the only one working on that branch (i.e. pushes changes to it) then you want to do a pull. A pull takes all the changes that were made on the remote branch and then tries to apply these to your local branch.
$ git pull