Initializing a Project

Updated on 28 Dec 2018

I need to link to another page.

git init

It could be that you’ve starting writing code for your project and now you’ve decided that you want to use git.

Goto the root directory of your project and initiate git.

git init


Modify the .gitignore for any files or folders that should be ignored.

Typically it may look similar to this where

  • .ext is ignoring all files that are of type ext
  • dir/ ignore the directory dir
  • config/*.php ignore all php files in the config directory (they might be handled by git-secret)

Configure Settings

You will probably need to configure some settings; such as username / password. These can be set on a global scale or per project. The next section deals with git configuration settings.

Initial commit and push

The initial commit and push is similar to what we would do in our day to day operations, however for the initial push we need to set the remote repo. Make sure I have files to add to the commit and then perform these commands

git add --all
git commit -m "initial commit"
git remote add origin
git push -u origin master
  • is the url to your remote repo. If you are using gitea then the url will be (on a local system) http://localhost:3000/brent/repo-name.git
  • git push -u origin master the -u is setting the upstream.

This means that later on we can just use git push and it will automatically go to the correct remote branch. Note, the remote only needs to be done once, however setting the upstream needs to be done for each branch.

Full git init for gitea

First login to Gitea and create a new repository. It will then display the list of commands below:

git init
git add
git commit -m "first commit"
git remote add origin http://localhost:3000/brent/repo-name.git
git push -u origin master

Full git init for gogs

This has not been done yet.

Pushing an existing repository from the command line

If you have an existing repository (i.e. copied something from work etc) then you can do the following.

git remote add origin http://localhost:3000/brent/python-notes.git
git push -u origin master

Cloning an existing repository

Cloning and existing repository is very straight-forward. For this example I’ll use github and find a project that I want to clone.

git clone

What this will do is download all the files associated with the project and place it in its own project directory.

Everything else is the same as the initial commit, except that we have already established the remote repo. We still need to set the upstream though.

git add --all
git commit -m "initial commit"
git push -u origin master

Adding empty directories

git ignores empty directories, however you may want them added because you need the directory structure kept intact. You can do this my simply adding a .gitignore with the following entry.


In this particular case what I am doing is ignoring everything in the directory except .gitignore. This way I am able to keep the directory in git but ignore all the files.