Git Common Tasks

Git like all source control systems supports many different ways to do workflow. I like the branching system that Microsoft’s VSTS team uses. If you find your current workflow painful, particularly around merging, I recommend taking a look at it.

TLDR: Each topic / hotfix (feature) branches off the master branch and merges when back to master when ready. When a release is desired, branch off master and name it the release name. If a hotfix comes up later, cherry pick the change from the master branch and merge it into the release branch.

To support this workflow you need to be able to do some common tasks in Git.

1. Setup (First time contributing to a project)

git init

git remote add origin [remote repository] *[remote repository]

git clone [remote repository] [local repository]

If you want to setup the current directory as the repository, use a ‘.’ for [local repository].

git clone [remote repository] .

2. Get Latest Code (you should be on the master branch)

git pull

3. Create Branch and Switch

git checkout -b [branch name]

4. Make your updates

5. Add Changes and commit

git add .

git commit -m "commit message"

6. Push Changes to Server and Generate Pull Request

git push [remote repository]

git request-pull [start commit] [remote server] master *[start commit] *[remote server]

If you are not sure of the [start commit], run the following command:

git log

If the commit does not have a tag value, you may use the hexadecimal value next to the commit.

That is a quick overview of how you make an update to a project using this workflow.

Other Git Topics