I had to learn a number of new git commands to work effectively and thought it'll be a great idea to share. The commands I will mention include cloning a repo, getting the latest changes, creating a branch, commiting your changes, creating a patch, sending a patch and applying the patches of other developers. I will share this by going through the process I use.
$ git clone git://git.apache.org/deltacloud.git
This is the first step one usually takes, I ran this last while working on my small contribution for applying for the internship. I'm pretty sure most people have used this before. Know an open source project you like, then you need to run this command and happy coding!
$ git pull
I run this code to get the latest changes on master before making any changes of my own. I do this often to keep my code up-to-date.
$ git checkout -b working_branch
This command basically create a new branch from master. This is where I will work on the code from. After writing code to a certain point, e.g, fixed a bug, you can commit your changes with the following commands. Please note that code relating to a certain issue should be commited as one commit. This is because they the different commits will create the different patches, and you definitely want relating code in one patch.
$ git add .
This will stage your changes for commit.
$ git commit -m "a commit message that makes sense"
This command, as you might have guessed, commits your changes. Most important thing here is the git message. It should summarize the your changes in a few words, and be very clear. It's important for these reasons: The message will be used as the subject of the patch (If you do not change this) and the other developers need to know that what your commit is all about. As I have come to learn, communication is key in open source projects.
$ git rebase master
Running this command is very critical - I am talking out of experience! This is apply your commits against master ensure ensure there are no conflicts. Next, you create your patches.
$ git format-patch master
This checks your commits against master and creates a patch for each commit. This will create .patch files for you. You probably want to add this to your .gitignore. Now to sending the patches.
$ git send-email -your-patches-
Before running this command, you will need to edit your .git/config file and fill out your details. After sending out the patches, you still have the .patch files hanging around, if you did not store them in a separate directory. What I do after this is run
$ rm -rf -your-patches-
This will simply get rid of the files for you. To apply patches by other developers, you simply run
$ git am name-of-patch.eml
This for a patch in email format. For patches in text format, use git apply.
There is the summary of some of the commands you'll find yourself using. Of course, there is a lot more and this no complete git documentation. I hope it helps someone starting out in open source. I am also pretty new to git, so feel free to leave comments with additions and corrections. :)