Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

11 May 2018

CLI instruction to work with git


For those who are still struggling with commit and updating their codes or got bored with SVN due to its tedious branching and complicated merging model, Git is the best practice with branches to a certain commit. Git allows you to create, delete, and change a branch anytime without affecting the commits. it works on the principle of Distributed version control

go to https://github.com/new ( provided you have a git account)

create your repository by giving its name

Git global setup
git config --global user.name "Punit Porwal"
git config --global user.email "punitporwal07@gmail.com"

Create a new repository
git clone https://gitlab.com/punitporwal/repo.git
cd repo
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Push an existing folder
cd existing_folder
git init    # Initialize the local directory as a Git repository.
git remote add origin https://gitlab.com/punitporwal/repo.git
git add .    # Add files in local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.
git config --global user.email "punitporwal07@gmail.com"
git config --global user.name punitporwal07
git remote -v #verifies the remote URL
git commit -m "Initial commit"
git push -u origin master

Push an existing Git repository
cd existing_repo
git remote rename origin old-origin
git remote add origin https://gitlab.com/punitporwal/repo.git
git push -u origin --all
git push -u origin --tags

    sample showing push to git


Distributed version control mechanism

known issue:

Git push error pre-receive hook declined
[remote rejected] master -> master (pre-receive hook declined)

solution:
GitLab by default marks master branch as protected (See Protecting your code /why). 

Open your project > Settings > Repository and go to "Protected branches", find "master" branch into the list and click "Unprotect" and try again.


For version 8.11 and above : how to protect

Generating your personal access token

navigate to git profile > settings > Developer settings > Personal access tokens > Generate new token  New personal access token  "nameit"  select scope Generate token 
copy token value

use this token at any place where needed

for example in openshift:

oc create secret generic git-secret --from-literal=username=punitporwal07 --from-literal=password=4f41599f5f99e84e7cc9f552ad6c731ce0573a6a


Br
Punit