Tuesday, October 16, 2018


GIT Command 1. Initialize git repository type command in the terminal: $ git init $ git add --all $ git commit -m "Initial Commit" 2. Create a new repository. Login into git repository
3. Locate git clone url
         e.g.   https://username@your..domain:7999 /yourproject/repo.git

4. Push the files to repository
        type command in the terminal: $ git remote add origin https ://username@yourname.domain:7999/yourproject/repo.git $ git push -u origin master 5. Error - failed to push some refs to 'https://username@bitbucket.org/yourname/yourproject/repo.git

       type command 

$ git pull --rebase origin master
$ git push origin master

hat way, you would replay (the --rebase part) your local commits on top of the newly updated origin/master (or origin/yourBranch: git pull origin yourBranch).
--------------------------------------------------------------------------------------------------------------

1.    Getting Help

Three ways to get the manual page (manpage) help for any of the Git commands

$ git help <verb>
$ git <verb> --help
$ man git <verb>
           e.g.  $ git help config
2.    Check Your Git Settings
$ git config –-list 3. 


a.     Check user name
To get user name for a specific repository 


$ git config user.name Or   $ git config --get user.name
Nitin 
To get user name for all repositories
$ git config --global user.name Or   $ git config --global --get user.name
Nitin
b.    Check user email
To get user email address for a specific repository
$ git config user.email Or   $ git config --get user.email
nitink@cdac.in
To get user email address for all repositories
$ git config --global user.email Or   $ git config --global --get user.emailnitink@cdac.in
3. Your Identity 
Set user name & email address. This is important because every Git commit uses this information
 To set user name for a specific repository
a.     $ git config user.name “Nitin Karale” 
To set username for every repository  
a.     $ git config --global user.name “Nitin Karale”
b.    $ git config –global user.email nitin.tkarale@gmail.com
4. Check remote url        To get remote url of repository $ git config --get remote.origin.urlhttps://nitin_karale@bitbucket.org/nitin_karale/sorghum.git

$ git remote show origin
* remote origin
       Fetch URL: https://username@domain/yourname/repo.git
 Push  URL: https://username@bitbucket.org/yourname/repo.git
 HEAD branch: master
 Remote branches:
    SorghumV1                tracked
    SorghumV2                tracked
    google-play-services_lib tracked
    master                   tracked
    sorghum-android-studioV2 tracked
 Local branch configured for 'git pull':
    SorghumV2 merges with remote SorghumV2
 Local refs configured for 'git push':
    SorghumV2                pushes to SorghumV2                (up to date)
    sorghum-android-studioV2 pushes to sorghum-android-studioV2 (up to date)


5.  Set remote url in initialize
a)    Initialize git first
$ git init
It shows initialize git
b)    Check remote url by using following command
$ git remote –v
origin  https://username@domain/yourname/repo.git (fetch)
origin  https://username@domain/yourname/repo.git (push)

If it is empty then use commandE.g. $ git remote add origin {repository-url}

6.    Make sure you have not set the GIT_COMMITTER_NAME or GIT_AUTHOR_NAME variables. You can check their values with the following command:
a.     $ echo $GIT_COMMITTER_NAME
         # prints the value of GIT_COMMITTER_NAME
Output - It’s NULL (if not set value)
b.    $ echo $GIT_AUTHOR_NAME
   # prints the value of GIT_COMMITTER_NAME
Output - It’s NULL (if not set value)

Set committer name & author name
a.     $ GIT_COMMITTER_NAME=Nitin Karale

b.     $ GIT_AUTHOR_NAME=Nitin Karale


7. Unstage an added file in Git. If you added a file by mistake, you can unstage it (but keep local changes) by saying

   $ git reset HEAD path/to/file        This is also what  $ git status will tell you

8.    Merging
After pull it will get merging
HCDC-PC8+Nitin@HCDC-PC8 MINGW64 /e/NVLI/automated-classification-tool (dev|MERGING)
Then use following command
$ git commit
     It shows git commit then use :q command

9.    Clone specific branch
                $ git clone –b {specific branch} {repository url}
      e.g
$ git clone –b dev {remote url}
10.    Shows remote branches & local branches
$ git branch
* master
$ git branch -a
* master
  origin/1-2-stable
  origin/2-0-stable
  origin/2-1-stable
  origin/2-2-stable
  origin/3-0-unstable
  origin/HEAD
   origin/master
$ git branch -r
  origin/1-2-stable
  origin/2-0-stable
  origin/2-1-stable
  origin/2-2-stable
  origin/3-0-unstable
  origin/HEAD
  origin/master
11.    Remove local untracked files from the current Git branch
a)     If you want to see which files will be deleted you can use the -n option before you run the actual command:
     $ git clean –n
 E.g.
  $ git clean -n
 Would remove src/main/webapp/WEB-INF/glassfish-resources.xml

b)     Then when you are comfortable (because it will delete the files for real!) use the -f option:
$ git clean –f
c)     Here are some more options for you to delete directories, files, ignored and non-ignored files
·       To remove directories, run
$ git clean –f -d or $ git clean –fd
·       To remove ignored files, run
$ git clean –f -X or $ git clean –fX
·       To remove ignored and non-ignored files, run
$ git clean –f -x or $ git clean –fx
12.    Stash - To record the current state of the working directory
      a) To record the current state of the working directory and the index, but want to go back to a clean working directory 
                        $ git stash 
b)    To show list of stash
       $ git stash list 
stash@{0}: WIP on submit: 6ebd0e2... Update git-stash documentation
stash@{1}: On master: 9cc0589... Add git-stash 
Or
                    $ git stash show 
Update git-stash documentation
Add git-stash 
c)     To pop stash
Remove a single stashed state from the stash list and apply it on top of the current working tree state
                        $ git stash pop

d)    To “Apply” Like pop, but do not remove the state from the stash list

     $ git stash apply stash@{0}

e)    “Clear” - Remove all the stash entries. Note that those entries will then be subject to pruning, and may be impossible to recover
               $ git stash clear
13.   Git ignore file 
       .gitignore  Remove ignores files which are tracked before git add

            a) Create a .gitignore file in project root

             b) Edit .gitignore file in notepad
             c) write all the files line by line you don´t want to add on the repository
               e.g.   
                      
           d)Then in your git bash you have to write the following line:
                             
                             $ git config --global core.excludesfile ~/.gitignore_global

             e) Commit all files 
                    
                            $ git rm -r --cached .

                            $ git add .
                                   $ git commit -m ".gitignore is now working"

No comments:

Post a Comment