Git - Usage and Tips

From wiki.openedev
Jump to: navigation, search

Usage[edit]

Need more info on Git

Install[edit]

bash> sudo apt-get install git
bash> sudo apt-get install git-email

Getting started[edit]

  • Clone repository
 bash> git clone git://git.denx.de/u-boot-spi.git
 
  • Create commit
 Check the status
 bash> git status  
 Add ~/.gitconfig
 bash> vi ~/.gitconfig    
 [user]
       name = Jagan Teki
       email = [email protected]
 [core]
       editor = vim
 edit files, example file1.c file2.c and dir1
 bash> git add file1.c file2.c and dir1
 bash> git commit -s
 << write something about commit message >>
 
  • Send patch
 Add ~/.gitconfig
 [sendemail]
       from = Jagan Teki <[email protected]>
       smtpencryption = tls
       smtpserver = smtp.gmail.com
       smtpuser = [email protected]
       smtpserverport = 587
  • Create one patch on top of HEAD
 bash> git format-patch -1
  • Send the patch
 bash> git send-email --to [email protected] --cc="Jagan Teki <[email protected]>" 0001-*.patch

Generate new SSH key[edit]

SSH key generation will give private and public keys, once the keys generated send the public key to remote repository server/maintainer so-that any pushes to remote repo is secure with SSH.

 bash> ssh-keygen -t rsa -b 4096 -C "[email protected]"
 # Creates a new ssh key, using the provided email as a label
 Generating public/private rsa key pair.

 Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

 Enter passphrase (empty for no passphrase): [Type a passphrase]
 Enter same passphrase again: [Type passphrase again]

Copy SSH keys from one machine to another[edit]

  • Copy id_rsa and id_rsa.pub to machine
  • Update the permissions
 bash> chmod 600 ~/.ssh/id_rsa
 bash> chmod 644 ~/.ssh/id_rsa.pub

Tips[edit]

  • Generate patches from HEAD to till SHA1
 $ git log --pretty=oneline <SHA1>...HEAD | wc -l > count
 $ git format-patch -`cat count`
  • Generate n number of patches from particular SHA1
 $ git format-patch <SHA1> -<num_patches>
  • Remove HEAD from remote repository
 $ git push -v remote +HEAD^:<name_of_branch>
  • Remove remote branch
 $ git push -v remote :<name_of_branch>
  • Push local tags to remote repository
 $ git push -v remote --tags
  • Push local branch/changes to remote repository
 $ git push -v remote <local_branch>:<remote_branch>
  • Pull remote branch/changes from local repository
 $ git pull -v remote <remote_branch>:<local_branch>