Pages

Label

Rabu, 30 Januari 2019

Some useful git command line

Hello Guys!!!  Hope You all are doing well!!!!.
Today I am going to share some useful git command. I think here no need to start  with my favorite question What is git. it is obvious that you people know about git.  

Git is a version control system (VCS) for tracking changes in computer files and coordinating work on those files among multiple people. 

it can be used to keep track of changes in any files. As a distributed revision control system it is aimed at speed, data integrity, and support for distributed, non-linear workflows. 

1. setting proxy in git

git config --global http.proxy http://my.company.com:8070
git config --global https.proxy https://my.company.com:8070

8070 is port number

2. Removing old git
Go to the project's directory: cd PROJECT_DIRECTORY
Remove all the git specific files: rm -rf $(find . -name ".git*")

3. Initialize a new git repository
Go to the project's directory: cd PROJECT_DIRECTORY and use init command.
git init

4. Using existing remote git repository
if you want to add any remote existing github or any git base project to your current directory. Then use following command :-
git remote add origin https://github.com/user-12/Example_project.git
git fetch

It will show following result
remote: Counting objects: 5700, done.

remote: Compressing objects: 100% (36/36), done.

remote: Total 5700 (delta 15), reused 2 (delta 0), pack-reused 5654

Receiving objects: 100% (5700/5700), 8.46 MiB | 222.00 KiB/s, done.

Resolving deltas: 100% (3325/3325), done.

* [new branch] Development -> origin/Development
* [new branch] master -> origin/master

5. Check out on a remote Git branch
After successfully fetching the remote branch you can use following command to do checkout
git fetch origin
git branch -v -a
git checkout -b Development origin/Development

on successfully checkout you will get this messages

Branch Development set up to track remote branch Development from origin.
Switched to a new branch 'Development'

Now every thing set up, do 
git rebase and 
git pull and start making new changes in your existing project.

6. Steps for creating patch
First check your project's status using status command
git status
Then add all your modified class
git add packages/apps/example_app/res/layout/example.xml packages/apps/example_app/res/layout/example_1.xml …...
Commit it
git commit -m “Initial project commit”
check commit log
git log
create patch
git format-patch -1
creating patch without commit
git diff >> example_patch_file.patch

7. Apply patch
patch -p1 < ./<working-dir>/0001-Added_example_feature.patch

8. Steps for reset code to latest commit & git pull
Delete all your changes and keep the latest changes , have on server
git log
git reset --hard commit_ID //  git reset --hard for current commit
git pull

Keep your local changes and get latest changes from servers
git stash
git pull
git log

Now if you want to apply your local changes then
git stash apply

Note :- 
It is recommended to do git fetch and git rebase before pushing your changes on Git.

9. Git Configuration
git configuration will give easy access of pull and push of files. 
git version  // show the current git version installed in your machine.
git config --global user.name "user-12"
git config --global user.email "user-12@examp.com"
git config --global --list // shows all global list.
With Git 1.7.9 or later, you can just use one of the following credential helpers:
git config --global credential.helper cache
... which tells Git to keep your password cached in memory for (by default) 15 minutes. You can set a longer timeout with:
git config --global credential.helper "cache --timeout=3600"


10. Git Ignore file 

  1. Create a .gitignore file by typing touch .gitignore
  2. Open the .gitignore file with a text editor of your choice and edit its contents to make sure you list all files in the project directory that you do NOT want to upload to your remote repository. List one file on each line, then save and close the .gitignore file.  

Happy Coding !!!

Thanks

Note:- Please proved your comment and suggestion for my post. It will energize me.

0 komentar:

Posting Komentar

 
[tutup]