Hello! I am Tamás Kálmán, economist by education, software support engineer by practice, a big fan of the web platform and an avid sailor.

Git operations

This is a note to self regarding git operations I do frequently or not so frequently, but sometimes I forget how some of them should be done. The operations, if path location is not mentioned explicitly should be done in the root of your Git repository you want to manipulate.

Create a local git repository and push it to my git remote repo

I usually push my local repo to a small server that I have, so that I can push and pull changes from different laptops I am working on.

Create git repository in the current directory

You need to initialize the Git repository in the project (current) directory, to create the necessary directory and file structure for git tracking metadata. git init

Add the files you want to track in your repository

You need to add the files, where you want to track changes and want changes to be committed during the next commit. You are basically staging the files for commit. You either specify a specific set of files or just add everything by using the dot (current directory):

git add .

Commit the files staged

Nothing special. You commit the changes in staged files to your repository.

git commit -m 'First commit.'

Create a bare repository on the remote machine

Log in to the remote machine command line, using the user you will use to connect with Git to it and create a directory preferably with the same name as your local project directory (Git repo if you will). I usually stick .git to the end out of personal habit.

mkdir reponame.git

Change to the repository directory:

cd reponame.git

Create a bare repository:

git init —bare

Now your remote end is ready to receive your local repo's data.

Add the remote repository target

You basically specify the target git URL of the remote git repository. No communication is done at this point, only the target is set.

git remote add origin remoteuser@remotehost:reponame.git

Push the local repository to the remote repo

You send the master branch of your local repository to the remote machine. You use this command to push your changes commited in the future to the remote repository as well.

git push origin master