To check-out a repository that you will be committing code to, it is best to clone it. A repository can be cloned into the current directory with the following command.
git clone [email protected]:Senzing/knowledge-base.git
This will list pending changelist as well as added/changed/deleted items
git status
git pull
git add <filename>
git diff
Note: You want to make sure your repository is synced to github before commiting your changelist to avoid a merge
git commit
This will open a text editor for you to comment the changelist
You should now push this committed change to github so others can pull it
git push
This will show the branches of the repository you have checked out, and which branch is currently active locally
git branch
This will show all the remote branches available for checkout first make sure you local repository is in sync with the origin:
git fetch origin
then list branches:
git branch -v -a
git checkout <branch_name>
You can also use
git switch <branch_name>
First create the branch locally, then push it to github
git checkout -b <branch_name>
git push origin <branch_name>
git branch --set-upstream-to=origin/<branch_name> <branch_name>
In repositories created after October 2020, the "main" branch is used.
GIT_CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
git checkout main
git pull
git checkout ${GIT_CURRENT_BRANCH}
git merge origin/main
git push
In repositories created before October 2020, the "master" branch is used. However, they've since been migrated to "main" in May 2022.
GIT_CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
git checkout main
git pull
git checkout ${GIT_CURRENT_BRANCH}
git merge origin/main
git push
first delete it locally
git branch -d <branch_name>
then delete it on github
git push origin --delete <branch_name>
No problem, we got you.
Make sure you are on the branch to which you have been committing.
git log
to check how many commits you want to roll back.
undo the commits with git reset HEAD~N where “N” is the number of commits you want to undo.
eg, to undo one commit:
git reset HEAD~1
now create your branch, switch to it, and continue on as if that didn't happen.
Do be sure to verify that you're only committing the changes you want with git status
Set up your name and email
git config --global user.name "Your Name"
git config --global user.email [email protected]
Prune deleted branches from your local when you pull
git config --global fetch.prune true
- Change the GitHub settings to keep your email address private
- Set your email address in Git to the noreply email address generated by GitHub
- Test pushing a commit to valiate settings changes.
Prerequisite: Install GnuPG
NOTE: The following steps have been tested on OSX and Linux.
If you encounter issues please refer to the respective GitHub documentation linked in the Additional Resources section below.
-
Generate a new GPG key.
- NOTES
-
Open Terminal / Git Bash.
-
Generate a GPG key pair.
gpg --full-generate-key
- When prompted input the number corresponding to the kind of key and press
Enter
.- Recommended input:
ECC (sign and encrypt)
.- If using ECC, input the number corresponding to the elliptic curve and press
Enter
. - Recommended input:
Curve 25519
.
- If using ECC, input the number corresponding to the elliptic curve and press
- If ECC is unavailable you can use
RSA and RSA
.- Recommended key size:
4096
- Recommended key size:
- Recommended input:
- Input the length of time the key should be valid and press
Enter
.- Recommended input:
1y
.
- Recommended input:
- Verify your selections are correct.
- Input your name and press
Enter
. - Input your email address and press
Enter
. - Optionally input a comment and press
Enter
. - Verify your selections, input
O
and pressEnter
. - Type a secure passphrase.
- NOTE: You will be prompted for this passphrase when running
git commit
The default cache for this passphrase is typically 2 hours.
See links in additional details for changing default caching values.
- NOTE: You will be prompted for this passphrase when running
- When prompted input the number corresponding to the kind of key and press
-
List the long form of the GPG keys.
gpg --list-secret-keys --keyid-format=long
-
From the list of GPG keys, copy the long form of the GPG key ID you'd like to use.
In this example, the GPG key ID is3AA5C34371567BD2
:$ gpg --list-secret-keys --keyid-format=long /Users/hubot/.gnupg/secring.gpg ------------------------------------ sec 4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10] uid Hubot <[email protected]> ssb 4096R/4BB6D45482678BE3 2016-03-10
-
Configure Git to use the key generated in the previous step.
-
Open Terminal / Git Bash.
-
Unset any existing git signing key format.
git config --global --unset gpg.format
-
Use the long form of the GPG key ID from Step 1.iv above to set your primary GPG signing key in Git.
In this example, the GPG key ID is3AA5C34371567BD2
:git config --global user.signingkey 3AA5C34371567BD2
-
Configure Git to sign all commits by default.
git config --global commit.gpgsign true
-
-
Add the GPG key to GitHub.
-
Open Terminal / Git Bash.
-
Use the long form of the GPG key ID from Step 1.iv above to export your public GPG key.
-
Paste the text below, substituting in the GPG key ID you'd like to use.
In this example, the GPG key ID is3AA5C34371567BD2
:gpg --armor --export 3AA5C34371567BD2 # Prints the GPG key ID, in ASCII armor format
-
-
Copy your GPG key, beginning with
-----BEGIN PGP PUBLIC KEY BLOCK-----
and ending with-----END PGP PUBLIC KEY BLOCK-----
. -
Login to the GitHub UI.
-
In the upper-right corner of any page, click your profile photo, then click
Settings
. -
In the "Access" section of the sidebar, click
SSH and GPG keys
. -
Next to the "GPG keys" header, click
New GPG key
. -
In the
Title
field, type a name for your GPG key. -
In the
Key
field, paste the GPG key you copied in Step 3.iii above. -
Click
Add GPG key
.
-
-
Optional: Use gpg-agent flags for configuring default caching for authentication or preset passphrase.
- See links in Additional Resources below.
Error:
gpg: signing failed: No such file or directory
fatal: failed to write commit object
Ensure GPG_TTY
is configured in the environment.
See Configure TTY for more details.