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 ( provided you have a git account)

create your repository by giving its name

Git global setup
git config --global "Punit Porwal"
git config --global ""

Create a new repository
git clone
cd repo
git add
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
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 ""
git config --global 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
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)

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