Starting git and github

I did not proof read this post! 🙂

I finally started using git again.

I tried using it some five years ago, but it was so user hostile, that I soon quit. First days using it were ok, but I had a few months break and didn’t remember anything, and so I eventually just gave up.
Now it’s time for another try. It seems the documentation is much better now, and there’s many more sites using it, than five years ago.

Git has one of the most user unfriendly interfaces of all time. It is inconsistent. But I’ll try to use it anyway.

There are probably great tutorials somewhere, and this is not one of them. I didn’t read a tutorial. I just googled every step. That’s why I ran into (small) trouble.

I first created an account for github some months ago. There are also other sites offering similar services. None of them are actually needed to use git, but it makes it easier when you can push your code to some external service and have it stored there.

Then I created a repository. Just a few clicks. Choose licence. MIT. It might have been a good idea to add a .gitignore file, but as the user interface for that wasn’t so clear, and I didn’t know what that was at the time, I did it later, and it was still easy.

Ok. So the trouble came when I did my first push. It had a wrong user name. It actually had the username of my computer account, which is just silly.

Here’s some quick notes what I should have done:

1. Cloned the repository from github to my local computer with:

git clone https://github.com/jonaskivi/rae_programming_language.git

It creates a new dir with the project name, so you don’t have to create a dir beforehand.

2. I should have created a .gitignore file at this point to ignore hidden OS X files. Such as .DS_Store.
Check to see if you have it already with listing all the files:

ls -a

Create the file like this (or edit it if you already have it). echo used together with > will output the text “.DS_Store” into the file .gitignore, which is then also created.

echo .DS_Store > .gitignore

You can also create it with a text editor, but I liked the above solution. I should really try to actually learn the command line. But not vim. Never vim. Today I learned how to quit vim!

3. I should have changed my author name and email. But nobody told me to do it. Here’s how. Change yourgithubusername to your github username.

git config --global user.email "yourgithubusername@users.noreply.github.com"
#inside your git dir, just in case, and if you need different emails for different projects.
git config user.email "yourgithubusername@users.noreply.github.com"
git config user.mail
#OUTPUTS nothing on my machine. Even though the internet says it should.
#instead I checked it with the following (~/ is you home dir.)
cat ~/.gitconfig
#OUTPUT: [user]
#OUTPUT: 	email = yourgithubusername@users.noreply.github.com

4. I should have changed default git editor from vim to nano. Nano has onscreen documentation. Vim does NOT.

git config --global core.editor "nano"

5. I copied all the files and directories that I wanted to be in this repository. With a file manager or however you want to do it.

6. Add all the files with

git add .

7. Check what’s happening with

git status

8. If there are files that shouldn’t be there. I did this. There could be some better commands with HEAD in them.

git rm rae_compiler/rae_compiler/.DS_Store 
#OUTPUT: error: the following file has changes staged in the index:
#OUTPUT:     rae_compiler/rae_compiler/.DS_Store
#OUTPUT: (use --cached to keep the file, or -f to force removal)
git rm -f rae_compiler/rae_compiler/.DS_Store 
#OUTPUT: rm 'rae_compiler/rae_compiler/.DS_Store'

So I had to use the -f flag to force it. I don’t like to force things.

9. Commit to your local git master branch thing.

git commit -m "Added ugly compiler code."

10. To push to github. (Only works if you cloned from there. If you didn’t, you’ll somehow need to link it.)

git push origin master

——————————————————————————-

11. If you forget the -m message thing, you can quit vim by hitting the escape-key on your keyboard, and typing “:q!” to quit without saving.

12. If you’ve already made the mistake of not changing your author. Here’s how to destructively change history. Don’t do it if this is not your project, or something. I didn’t understand the script on github. This one I could understand. Franz Kafka is the old false author name I had.

git filter-branch --commit-filter '
         if [ "$GIT_COMMITTER_NAME" = "Franz Kafka" ];
         then
                 GIT_COMMITTER_NAME="your_new_name";
                 GIT_AUTHOR_NAME="your_new_name";
                 GIT_COMMITTER_EMAIL="your_new_name@users.noreply.github.com";
                 GIT_AUTHOR_EMAIL="your_new_name@users.noreply.github.com";
                 git commit-tree "$@";
         else
                 git commit-tree "$@";
         fi' HEAD

And then tried:

git push origin master
To https://github.com/jonaskivi/rae_programming_language.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/jonaskivi/rae_programming_language.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Rejection feels so bad sometimes.

I did “git pull”. It asked me about the message. But I had the Vim default editor. I googled how to quit it! Hit “escape key” and type “:q!” to quit without saving.

git pull

Probably you can put the message in there with -m. Didn’t try it yet.

#OUTPUT: error: There was a problem with the editor 'vi'.
#OUTPUT: Not committing merge; use 'git commit' to complete the merge.

Maybe it was my/vims fault that it didn’t merge.

git commit -m"Trying to fix git author :("

Committed the merge for me.

git push origin master

Pushed it to github. And my name was hopefully fixed, but I’m not sure. The old name still shows up in Github commits though.

End of post. Hope you found what you were looking for.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s