My most used Git commands on open source projects.

 

The basic step when committing to open source projects is to fork the project.
Then the process is easy you create your branch and you make a pull request. However from time to time you need to adjust you branch based on the latest changes.

This is how you sync your fork to the original one.

git fetch upstream
git checkout master
git merge upstream/master

This is pretty easy but you might want something more than just synchronizing with the original repository.

For example there might be a pull request which never got merged for various reasons and you wan’t to pick up from where it was left.

The first step is to add the repository needed

git remote add $remote_repo_identifier $remote_repo_url

So we just added another remote to our repository.

The next step is to fetch the branches from the remote.

git fetch $remote_repo_identifier

Then you can switch to the branch of your choice, continue make a new branch and continue with a pull request.

git fetch $remote_branch

Remove the upstream

 git remote remove $remote_repo_identifier

And set the upstream to your original one

git push --set-upstream origin $remote_branch

Git repositories through ssh.

So you have an ssh server?
Great!!! Time to setup some git repos.

If you don’t already have a git user and git installed

sudo adduser -m git
sudo apt-get install git

You can use the git account either through normal password authentication or by using private and public ssh keys. Your choice 🙂

Then set up the repo.

cd /home/git/
mkdir mygit.git
cd mygit.git
git --bare init

And you are ready to go.
Open a terminal on your pc and just do

git clone git@yourserverip:/home/git/mygit.git

In order to share the project with other users you can share the project with a specific group, for example the ‘developers’ group.

chgrp -R developers gitrepo
chmod -R g+swX gitrepo