Skip to content

Instantly share code, notes, and snippets.

@AdamMagaluk
Created September 17, 2013 14:40
Show Gist options
  • Save AdamMagaluk/6595244 to your computer and use it in GitHub Desktop.
Save AdamMagaluk/6595244 to your computer and use it in GitHub Desktop.
Git Workflow

Git Work Flow

This document will describe our process or using Git and Gitlab for managing our software development.

Tutorial Format

All text blocks like the one below are intended to be ran from the command line or Git Shell on Windows.

do somethinmg

Clone the Test Repository

git clone [email protected]:AdamMagaluk/test-project.git

The command above clones the test repository, when cloned the current branch is master.

Move into project

cd test-project

Branching

We use branches to separate development code vs stable production code. Branch names can be any string of characters including forward and backslashes. All development should happen in one of two branches:

a) A person developer branch named "yourname/devel" eg. adammagaluk/devel is my person developer branch. This branch is for general development on new repositories or minor updates to the code where it does not relate to a clearly defined feature.

b) A new feature branch named "featured/somefeature". Used a lot when adding new features on existing production code.

We use a setting in Gitlab to lock the master branch meaning only the repository owner can push changes to it. All changes from anyone else need to go through a merge request using Gitlab's interface, this allows us to handle code reviews before pushing into production code.

List Branches

To list all available branches run, the "-a" tells git to show us remote branches as well.

git branch -a

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/adammagaluk/devel
  remotes/origin/master

As you can see there are two branches my person development branch "adammagaluk/devel" and "master". remotes/origin/HEAD is a symbolic branch which is checked out when a clone happens.

Creating a Branch

Lets create a new person development branch.

git checkout  -b johndoe/devel

This command not only creates a new branch but switches your local directory to that branch. Thus all changes/commits/pushes from that branch will only effect that branch.

Create a file using an editor or some means. "touch in linux creates an empty file"

touch somefile

Tell git about the somefile

Files not specifically added will not be tracked in version control.

git add somefile

Commit the change

This tells Git that we've made some changes to one or more files and want to commit all files to that state in version control. At any future point we could reference the exact state when we committed the files.

git commit -m "Added somefile to the repo"

Push changes from branch johndoe/devel to gitlab

Pushing sends the johndoe/devel branch to the origin, origin is the remote repository we cloned from in the beginning.

git push origin johndoe/devel

Feature Branches and Merge Requests

Ok, say someone wants a TODO file in repository, they even might add a issue in Gitlab to keep track of the progress of this feature.

Well this feature could take a while and all code accompanying it should be able to be easily tracked and segmented so lets create a feature branch for it called "feature/todofile".

git checkout -b feature/todofile

Then create the file and add it to the repository like we did above.

Commit all changes, Note: the -a in git commit tells git to commit all modified files not only added/deleted files.

git commit -a

Push to gitlab

git push origin feature/todofile

Now Create a Merge Requesst

Using Gitlab's interface create a new merge request from "feature/todofile" to "master" and assign the request to one of the owners of the repository.

Once approved, it will be in the master branch.

Congrats, that should get you going developing on Git and Gitlab using our workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment