# Saturday, 30 January 2016

I admit that I am a novice when it comes to Git. But I recognize the importance of this version control system, so I documented the most important commands.

Git is a distributed version control system, so it is necessary to commit changes to a local repository (a repository on your local computer) before pushing those changes to a central repository that can be shared by others.

Commands

My needs are simple. In the vast majority of cases, I want only to get the latest code, make my changes, save them to a local repository, and share those changes with others. Git contains a lot of commands, but the following git commands suffice for most of my needs:

  • git init
  • git config
  • git add .
  • git pull
  • git commit
  • git push

Here is a brief description of each command:

git init

Intialize an empty Git repository

git config

Store information, such as username and email address in a local config file, so you don't need to re-type it later.

git remote add

Associate the local git repository with a remote repository

git add

Adds files in the current folder to the git repository

git commit –m “Comment about change

Commits changed files to the local repository. The “-m” switch allows you to provide a comment describing the code you are committing.

git pull repositoryname branch

Retrieves code from the remote repository and merges it with your local code

git push repositoryname branch

Pushes any changes from your local repository to a central repository

Workflow

My usual workflow is below. It assumes my code is in the local directory c:\development\MyProject and that the remote repository is named “myproj”.

Starting a new project

At github.com, create a new repository

cd \development\MyProject
git init
git config --global user.name "David Giard"
git config --global user.email djgiard@hotmail.com
git remote add origin https://github.com/DavidGiard/nameofmynewrepository.git
git add .

git commit -m "Initial revision"
git push origin master 

After I make a change and test it and it seems to work:

git pull origin master
// Test that the application still works after pulling and merging other developers’ changes
git add .
git commit -m "My change"
git push origin master

ALM