Skip to content

Instantly share code, notes, and snippets.

@sriramster
Last active November 1, 2020 15:07
Show Gist options
  • Save sriramster/cfd870a7ae472ed9b023 to your computer and use it in GitHub Desktop.
Save sriramster/cfd870a7ae472ed9b023 to your computer and use it in GitHub Desktop.
git flow

Git stuffs

Some basic commands. Ignore if you are already familiar with these stuffs.

Creating a new repo.

git init $PATH

Path needs to be empty or could have source files, except a .git folder.

git add $filename

Adds file to git repository

git rm $filename

Removes file from git repository

Collabarative development stuffs. (Just basics ignore)

In case remote git repository exists, use the following to update.

git remote add $name $url

Add's a remote url to your .git/config lets you start off collabarative development.

git fetch $branchname

Will fetch content from remote repository.

Maintaining sanity of local repository.

Never create a branch for every code push or commit that you do. Use tagging like below.

Create tag's if necessary, create tags for important commits like a merge from upstream contiki. Or deliver some important bug fix to a protocol stack.

Creates a tag with $tagname

git tag $tagname

Delets a tag with $tagname

git tag -d $tagname

Branching stuffs.

Always, work on one developmental "branch" uproach. No need of pushing any changes of this branch to 'master'. Though it is "ok" to have them as branches along with master in the github repo.

git checkout -b $branchname

Checkouts a new branch with $branchname.

Push/Pull code. If you are working on collabarative devel, and people could access your branch always do a fetch before you push code onto the git remote repository. i.e

git fetch origin

'Origin' would fetch code from a branch with name origin/$branchname. Then it means someone has added some changes to your branch. Then you would have to merge these changes before pushing to avoid any rejects.

i.e

git push . origin:origin/$branchname git merge origin/$branchname --no-ff --no-squash --no-commit.

The above command, would not commit the code. Have a look before commiting and pushing.

Once everything is fine.

git push $branchname.

For a fetch & merge with no real checks.

git pull origin

On the checked out branch, the above command would be useful. But be careful always.

Others

git status

Gives you the status of current local git repository.

git stash

Used to move to the commit before the working copy, really useful.

git rename $branchname

Used to rename a git branch.

Committing

git commit -s -m "Commit message"

-s is used to signing Patches.

-m says whatever follows after this option is the commit message.

Creating patches.

Once you've worked and commited your code on local repository. Use this command to create a patch for the HEAD commit hash of your local repository

git format-patch -n HEAD^

This would create a patch file on the path where run the command.

git send-email $PATH_FILE

Could be used to send the patch file over email to the maintainer for review, and merging.

~/.gitconfig example Please check this

The below is just a sample .gitconfig file from my filesystem. There are other fancy stuffs, I've kept it simple.

===== [user] name = Your Name email = your_email_id@host [color] true [diff] color = true [status] color = true [core] editor = emacs [sendemail] smtpEncryption = tls smtpServer = your_smtp_server smtpUser = your_smtp_id smtpServerPort = 25 bcc = your_email_id [push] default = simple

For anything else, have a look at git manual. Or ping me just in case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment