Showing posts with label Git. Show all posts
Showing posts with label Git. Show all posts

Thursday, 28 April 2016

What are basic git commands ?


Configuration

Configure user name and email
git config -global user.name “SHAAN”
git config -global user.email shaan@gmail.com

Create new Local git repo
git init

Connect your local repository to a remote server (First time)
git remote add origin <server>

List all configured remote repo
git remote -v


Operations

Checkout a repo
git clone /path/to/repository
git clone username@host:/path/to/repository

List changed files at your side

git status

Add one or more files to staging 
git add <filename>git add *

Commit changes to head of the local repo
git commit -m “Commit message”

Commit all changes (to local repo)
git commit -a

Push changes to master branch of Remote repo
git push origin master


Branches

List all branches
git branch

Create new branch and switch to it
git checkout -b <branchname>

Switch to other branch
git checkout <branchname>

Delete branch
git branch -d <branchname>

Push branch to remote repo
git push —all origin

Delete a branch from remote repo
git push origin :<branchname>

Fetch the changes from remote repo
git pull

Merge a different branch in your branch
git merge <branchname>


Tagging

Create a tag
git tag 1.0.0 <commitID>

Push all tags to remote repo
git push —tags origin

Revert back the local changes
git checkout — <filename>

Wednesday, 27 April 2016

How to integrate github with Jenkins ?


Github plugin can be used to receive push notifications that can trigger a Jenkins job.

Install Github plugin

  • Open Jenkins home page and Login as Admin (if security is enabled)
  • Click manage Jenkins
  • Click Configure Jenkins
  • Go to Manage Plugins link on left side
  • Select Github plugin from available plugins
  • Click Download and Install
  • Restart Jenkins


Configuration of Github project in a Jenkins job




  • Open Jenkins home page
  • Select the job
  • Click Configure link on left side
  • Inside Source code management section, Enter URL of Github projecthttp://github.com/username/project
  • For authentication, provide username / password in advanced... options.


Receiving the push notifications from GitHub
  • Open Jenkins home page and Login as Admin (if security is enabled)
  • Click manage Jenkins
  • Click Configure System
  • In Github Web hook sectionselect auto-manage hook URLs

    OR
  • In Github Web hook section, select Manually manage hook URLs
  • Go to Github project page
    • In Service Hooks tab, select Post-Receive URLs hook
    • Add URL <root_URL_of_Jenkins>/github-webhook
  • Open Jenkins home page
  • Select the job
  • Click Configure link on left side
  • Select Build when a change is pushed to GitHub and Save.
  •  

How to integrate git with Jenkins ?


Plugin site : https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin

Git can be used to checkout the code in Jenkins jobs using Git plugin of Jenkins.

Install Git plugin

  • Open Jenkins home page and Login as Admin (if security is enabled)
  • Click manage Jenkins
  • Click Configure Jenkins
  • Go to Manage Plugins link on left side
  • Select Git from available plugins
  • Click Download and Install


Configuration of Git repo in a Jenkins job

  • Open Jenkins home page
  • Select the job
  • Click Configure link on left side
  • Inside Source code management section, Enter URL of Git projecthttps://www.myrepo/git/projects/myproject.gitBy default, it will checkout all branches of the repository
  • To build a particular branch, provide branch name
  • For authentication, provide username / password in advanced... options.


Saturday, 23 April 2016

How to get code from GIT using GIT Bash ?


Get the code from repository
cd "C:\Users\workspace"
$ git clone https://www.forge.orange-labs.fr/plugins/git/csr/project.git

How to check your modified file status using GIT Bash ?


Check modified files
$ git status
On branch master
nothing to commit, working directory clean


Add new file in your local
$ git add README


Check again the modified files
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD &lt;file&gt;..." to unstage)
    new file:   README


Check status with short info
$ git status -s
 A README

What does "Changes not staged for committed" means in Git ?


When you run "git status" command , you may see the warning message “Changes not staged for commit” for some files like,

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
    new file: Hello.txt

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
    modified: newFile.dat

It means that a file that is tracked has been modified in the working directory but not yet staged.

 

Solution
To stage it, you run "git add" command.
"git add" is used to begin tracking new files, to stage files, and to do other things like marking merge-conflicted files as resolved.

It acts like “add this content to the next commit”

$ git add newFile.dat
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
    new file:   hello.txt
    modified:  newFile.dat
 

How to commit changes in Git ?


Any file which is still unstaged, i.e. Any file you have created or modified that you haven’t run git add on since you edited them – won’t go in this commit.

These will be there as modified files on your disk.

Run below command to run : 
$ git commit

How to use GIT on windows with command line interface ?


Download Git for Windows from 
https://git-for-windows.github.io/

It will install 2 main components :
 1. Git GUI

 2. Git Bash


Checking Git bash

Display your file status (Checks which files are in which state)
$ cd "/local_path"
$ git status