Notes to self: GIT

Mnemonics are called mnemonics because they are hard to memorize.

The following is more or less just a reminder for myself. A good online reference is Git Reference for the basics.

To add one file (assuming /bin/sh and common GIT naming):

git add a_file.c
git commit -m "Added a_file.c with the miraculous function one_file()"

To add more than one file, commit them all and give all of them the same comment. I used this to commit the three files necessary for the most basic build.

git add tommath.h tommath_class.h makefile
git commit -m "Addition of a_file.c with function one_file()"

Push all of them to remote GIT repository

git fetch upstream
git push -v  origin master

the line git fetch upstream checks the original for intermediate changes that might ruin your daymake what you did obsoleteintersperse with what you have done. If something happened (not in libtommath, last change is a long time ago) you need to do git merge upstream/master where master is the main branch of upstream which is the remote original one. The full command merges that branch with your local branch. Uhm…you can find out the aliases (they are not fixed, the above are just the commonly used ones!) with git remote -v . Here are my results:

czurnieden@home:~/GITHUB/libtommath$ git remote -v
origin	https://github.com/czurnieden/libtommath.git (fetch)
origin	https://github.com/czurnieden/libtommath.git (push)
upstream	https://github.com/libtom/libtommath.git (fetch)
upstream	https://github.com/libtom/libtommath.git (push)

To find out what happened in the meantime before fetching

git log upstream/master ^master

If unsure which branch you are hacking right now

git branch

Say:”Ooops!” and change to branch testing which you have made with git branch testing

git checkout testing

Check if you haven’t forgoten any file to commit:

git diff-tree --no-commit-id --name-only HEAD~20..HEAD

The number 20 is the maximum number git checks, so if you commited more, increment that number.

Advertisements

One thought on “Notes to self: GIT

  1. TechnologyLeadership (@technlead)

    This is a useful article with detailed meaning of the basic GIT commands.

    Also, “git pull” can be used before “git push” to pull in the latest code changes into the branch before our code change is finally pushed to the remote repository. This ensures there will be no merge conflicts.

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