Tutorial Level: Medium
This post is intended for readers who already have experience with a version control system.
For official documentation, please reference:

What is git?

Well chap, git is arguably the most popular, modern source code management (SCM) tool in use today. You control it with the command line. When software developers want to collaborate on a project together, the last thing they want to do is worry about stepping on each other’s toes. Git allows developers to write code together without losing changes and revert back from any unwanted changes. With git, you can easily track your project’s codebase, keep it up-to-date, and control the workflow. Lastly, git is extremely light-weight and best of all, it’s open-source.

Luckily for you, it doesn’t take one to know one…
Definition of git

 
Onward!

Need a clean git setup?

Lesson 1: Clean, Initialize, and Branch a git repository.

  1. Clean

    Pro tip: Don’t nest instances of git.

    If you have a messy git implementation and need to start over, here’s how to recursively remove all git-repositories from a directory. Note: This will Not delete your project files.

    Open your terminal and navigate to troubled directory.

    Check to see if there is a ‘.git’ repository file.

    ls -lah 

    Remove all git related files (force recursive).

    rm -rf .git* 
  2. Initialize

    git init 

    See repo status

    git status 

  3. Branches

    See all branches

    git branch -a 

    Add branch

    git branch <branch> 

    Checkout branch (switch to branch)

    git checkout <branch> 

    Push branch and set the remote as upstream branch

    git push --set-upstream origin <branch>

I’m Ready

Lesson 2: Pull, Commit, Push and Merge.

  1. Pull

    Update your current branch

    git pull

  2. Commit

    Check status of files

    git status

    Add files to ‘staging’ to be committed

    git add <file>

    Commit all staged files

    git commit -m "<message>"

    Stage and commit all files in directory

    git commit -am "<message>"

  3. Push

    Pro tip: Always pull right before you push to avoid overriding someone else’s recent push.

    Push your committed files

    git push

  4. Merge

    Combine specified branch into current branch

    git merge <branch>

Yes, master.

Lesson 3: Guidelines & Branch Design

  1. Guidelines

    Pull before you push.

    Leave brief, meaningful messages when you commit. When you need to find a specific change, ambiguous messages will not help you or your team.

    Frequent smaller commits tend to be easier to manage than infrequent large commits.

    Don’t assign users to work on the same file. This will minimize overriding and merge conflicts.

  2. Branch Design

    Use multiple branches: master (remote), develop (remote), and ‘your initials’ (local).

    Work on local branch. Teammate’s all push to develop. Team Lead merges develop to master.

    Master branch is your production branch. Always keep it in a working state. Always merge to master. Pushing is prone to more errors, so only push when you absolutely have to – such as a hotfix.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>