To make sure you will never lose your code, store your project on an online repository hosting service. No matter if you already have some work in progress on your local machine, or you are starting the project from scratch – backup your code online as soon as possible.
You are starting the project from scratch
Log in to your account on Github/Bitbucket. Create a new remote repo – check out the documentation for GitHub or Bitbucket to learn how to do this. Find the link to your repository, generally it is placed with the
Clone option – once again visit GitHub or Bitbucket docs if you need to. On your local machine go to the directory where you store all your projects, eg.:
and clone the link to your new remote repo:
This command will create in your current folder the project directory that is already linked to the remote repository and named after it.
Whatever files you add there, will be tracked by git unless you list them in the
.gitignore file. It keeps information about which files should be ignored by git during commits. Usually you will put there things that are sensitive – like passwords or API keys; wouldn’t be useful to other collaborators – like IDE files; and assets – like minified js/css files and external libraries.
You already have project files on your local machine
Initialize the repository in the main directory of your project:
and check its status:
You will see all files in the project marked red – git recognizes them as new but does not track them yet.
.gitignore those which you wish to keep untracked. If you check the status again, they won’t be listed any more.
To keep track of all the others, add them to git:
Anothershows all tracked files marked green. Now you can make your first commit:
Find the link to your remote repository, it is usually placed with the
Clone option – check out docs for cloning a repo in GitHub or Bitbucket if you can’t locate it. Now you can push the project to your online repo binding the local master to the remote one using
Setting the upstream with the -u option allows git to track the changes between remote and local repo, thanks to that you can later useand without specifying the branch.
What is next?
You will need more branches than one. For now create the
develop branch, alongside the
Now you can list all your branches
- stored locally:
- stored online:
Remember to commit small, commit often and regularly push to your remote storage!