How Do You Clone Down a Specific Branch of a Repository from Git?

Problem scenario
You want to clone a specific branch from Git.  But you do not want to clone the master branch.  How do you clone the branch named “develop”?

Solution
1.  Clone down the repository as normal with a command like this (but replace <SSH or HTTP constructor of repo> with the remote repository):
git clone <SSH or HTTP constructor of repo>

2. 

How Do You Unprotect a Git Repository That Is in a GitLab Project?

Problem scenario
You have a Git repository that is protected in a GitLab project.  You want to allow developers to upload code directly to the master branch (not alternative branches).  What do you do?

Solution
It may be more advisable to work with a branch of a git repository.  This is a basic solution for testing or those instances when you want to work directly with the master branch.  

What is GitOps?

Question
What is GitOps?

Answer
GitOps is a declarative method of managing infrastructure that is driven by committing code into a version control system. GitOps is an indirect, and usually imperative, approach to systems administration that gives a detailed history of past operations.  GitOps is the practice of adding code to a Git repository to trigger an operational event (such as rebooting a server, creating a user account,

How Do You Remove a File from a Git Repository so the Old Versions Are Eliminated?

Problem scenario
You accidentally uploaded a file with sensitive data (e.g., hard-coded credentials such as a database username and password) to a Git repository.  You want to eliminate it from the Git repository so all of its history are removed from the previous commits and it is unretrievable.  How do you do this?

Solution
WARNING:  This will delete data.  Some people rely on Git repos as a disaster recovery product. 

How Do You Delete the Git Credentials You Entered Into Jenkins for “Source Code Management”?

Problem scenario
In a Jenkins job there is a “Source Code Management” section.  You checked Git and entered credentials.  You entered the same username twice (or more).  Now you want to delete some of those users to be able to know which (unique) password is being used.  What should you do?

Solution
It isn’t always easy to find where the credentials for your Git repository are stored. 

How Do You Use the .gitignore File?

Problem scenario
You want certain files to be ignored when you do a git add –all.  Later you want to run a “git commit” and a “git origin push master” but you do not want certain files included.  While developing a solution and modifying files, you place binary files or change source code to include sensitive passwords in the same directory as your locally saved Git repo that you pulled down. 

How Do You Set up a Basic CI/CD Pipeline with GitLab and Jenkins?

Problem scenario
You want to create a rudimentary CI/CD pipeline (one that is simple and has no QA or automated testing of code).  You want to trigger a deployment of code upon code being checked into a Git repository.  You want to set up GitLab and Jenkins to be the main servers of this pipeline.  You have two other servers; one is for developing code on and checking code into a Git repository and the other server is for receiving code once it is checked into GitLab. 

How Is the Password Set for a Challenge for a Password from a “git clone git@…” command?

Problem scenario
A “git clone git@…” command prompts the user for a password.  What is the password or how is it set?

Solution
The authentication for such a git command is usually done by the individual servers not through Git itself.  You should go to the server with the source repository, and run this to change the password to something you know:

sudo passwd git

Alternatively you could change the owner and group of the .git file or the permissions of the git file.

How Do You Fix a Non-Terminating (Hanging) Command Such as “git push origin master” ?

Problem scenario
The command “git push origin master” hangs. What should you do?

Solution
Cancel the job with ctrl-c.  (Hold the “Control” key and tap the “C” key.)

For the target .git repository, does the file have the owner and group associated with the “git” user?

If you used the git user in the “git clone” command (as in “git clone @…”) but then changed the owner and group of the .git repository to something else,

What Does the “git rebase” Command Do?

Problem scenario
You are familiar with codebases in the context of configuration management or version control.   How can you invoke “git rebase” to learn more about git?

Solution
If you use the man page for “git rebase” you see this phrase to define “git rebase”:  “Forward-port local commits to the updated upstream head”

What does “Forward-port local commits to the updated upstream head” mean?