How to git

Handy things to know

click Super cool tutorial you should do


  • master repo -> the repository you forked from
  • user repo -> the repository that's on your account ( the fork you created)
  • remote -> a reference to the online repo

explaining commands


Docs -> Click me

Fetching will retrieve updates from the given remote [remote]

$ git fetch origin will fetch new changes from the remote called origin.

How ever doing a git fetch will not update the files.

It will only update branch history with changes.

So you can merge or rebase or create a branch with the newest data.

$ git fetch [remote] [branch] or git fetch --all


Docs -> Click me

Pushing will update your chosen repo with new changes and new branches that you created locally

The nicest way to push in my opinion is.

$ git push -u [remote] [branch]

This will update the chosen branch on the chosen repo with new changes. If the branch doesn't exist yet it will be created.

If you want to create a new branch on the remote with the current changes of the branch you are on.

$ git push [remote] [branch you are on]:[new branch]

Example we have a branch called bahb-1023 and we want to push that to the remote with a different name.

$ git push [remote] bahb-1023:bahb-1024


Docs -> Click me

Checking out in git means switching branches.

Example I am on the branch master and want to go to the branch development.

If that branch already exists i do something like this

$ git checkout development

If the branch doesn't exist yet you can do something like this.

$ git checkout -b development

this will create a new branch development and will make that your active branch.

To check if you are on the correct branch type.

$ git branch this will show you with highlighting which branch you are on.

You can also checkout from a remote.

$ git checkout -b [new name] [remote]/[branch]


You want a new branch named - 'new-branch' You want to create that branch from a remote called 'bahb' and using the branch 'online-branch'.

$ git checkout -b new-branch bahb/online-branch


Docs -> Click me

Fork party

what is a fork?

When you fork a repo it creates a fork of the repo of it on your account.

To play and tinker with.

Some documentation about forking Click me

In short go the the repo you want to have and click fork.

Fill in the information and bam you have cloned the repo and its on your account.

clone the fork

After you did that you go to your fork on in your own repos.

If you want to use ssh to retrieve the clone you should read this tutorial -> how to ssh.

You can also just clone as a zip or https clone.

Now on your computer find a nice place to dump the project on.

On that directory open the gitbash terminal and type.

You can find the clone url at the root of the repo

Here you can also select what method you want to use

to lazy to type the url this is the syntax

ssh users

git clone

https users

git clone

Or if you cloned it with a zip you just extract the zip file in the designated directory.

setting up a remote

To get the new updates from the master repo you should make a remote. Remotes track the online repo.

so if you use git fetch it will update the commits for you and you can grab them.

To add a remote use git remote add <remotename> <remoteurl> The remote name is something you can fill in your self.

The remote url is the url you can clone a repo with

you can find that url by checking the repo site.

Now if you do git remote -v

you will get 4 results

  • origin
  • origin
  • remotename - the one you chose
  • remotename - the one you chose

Starting a story

Say i want to work on a story thats called BAB-1234.

And our masterepo remote is called bob.

And the branch we want to use is development

First make sure you have the recent branch updates.

You do that by git fetch origin To update changes from our personal repo.

Also you must grab the changes from the masterrepo like this

remotename is the remote you named in the previous chapter. git fetch remotename

If you want to specify a branch you can do something like this.

git fetch remotename branchname

So now we know everything is updated we can create a new branch from the master repo.

git checkout -b branchname remotename/branchname

For the example story we would do something like this.

git checkout -b BAB-1234 bob/development

the -b will create a new branch for us and also go into that branch.

To make sure you are in the branch type

git branch

you will now see a result something like this

  • master
  • development
  • *BAB-1234 - green color

Done for today

When you are done for the day or you finished your code

You first check for new changes by fetching the newest code.

git fetch remotename

If there are changes you need to rebase them like this

git rebase remotename/branch

Now we know that you have the newest changes and can safely push it to the remote.

Before you can push it check your status and see if there some weird files.

in the git bash you type

git status

You will get a nice list about what files are changed or added.

when you checked everything and you are oke with it you type.

git add . this will add al the files.

If you want to add specific files to commit you can add them manually like.

git add ./somedirectory/somefile.txt

This will add that file and if you do a commit it will commit the files that were added.

You can also add files with your commit like this

git commit -m "Added some random files" some-file some-file2

Now you type git status again and hopefully see working directory clean.

Now you want to create a commit you do that by typing

git commit -m "information on what you did"

Now you want to push it to the online repo by doing.

git push origin branchname

This will push the new branch to the repo.

The nice thing is it will not update the dev branch but it will create a shiny new branch so everything is nice and isolated.

if you finished the assignment

When you are satisfied with the result you can ask for a pull request to the master repo.

You do that by going to your repo on the Bitbuckit website.

Then you click on create pull request and check if the branches are correct.

The left side should point to your new branch.

The right side should use the master repo and point to the development branch or any specific branch of the master repo

Compare the changes and check for conflicts or mistakes.

If you want to notify someone that you created a pull request and that they can judge it.

You should add this persons name to the reviewer list.

If everything looks fine and you agree with the changes you click on the Create pull request button.

You fill in the asked information and click on create pull request.

Now it is the admin job to check the code and merge it with the development branch.