DB-hub Technology 未分类 Git quick start

Git quick start

STEP1: Initialize git into your current working repository

mkdir sample
cd sample
git init

STEP2: Create a new remote, name it “origin”
– Adding the location of your remote repository where you wish to push/pull your files to/from

  • Your remote repository could be anywhere on github, gitlab, bitbucket, etc.

  • Here origin is an alias/alternate name for your remote repository so that you don’t have to type the entire path for remote every time and henceforth you are declaring that you will use this name(origin) to refer to your remote. This name could be anything.

  • To verify that the remote is set properly type : git remote -v

git remote add origin git@github.com:User/UserRepo.git

STEP 3:

create a branch, for Giblab, default is “main”

git branch -M main

pull from remote

git pull origin main


Username for 'https://github.com': xxxx@gmail.com
Password for 'https://xxxx@gmail.com@github.com':
remote: Invalid username or token. Password authentication is not supported for Git operations.
fatal: Authentication failed for 'https://github.com/???/xxxx.git/'

Option 1: Use a Personal Access Token (HTTPS)

1.Go to GitHub → Settings → Developer settings → Personal access tokens

2.Click “Tokens (classic)” → Generate new token → choose:

  • repo scope (for private repos),
  • set expiration (e.g. 90 days).

3.Copy the token (you won’t see it again).

4.when Git asks for your password during git pull or git push:

  • Username = your GitHub username
  • Password = the token you just created

Or you can store it like this:

git remote set-url origin https://<USERNAME>:<TOKEN>@github.com/???/xxxx.git

Option 2: Use SSH Keys (Recommended)
1.Generate SSH key (if you don’t have one yet):

ssh-keygen -t ed25519 -C "your_email@example.com"

Press Enter to accept defaults.

2.Add the key to your SSH agent:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

3.Copy the public key:

cat ~/.ssh/id_ed25519.pub

Copy the output.

4.Go to GitHub → Settings → SSH and GPG keys → New SSH key, paste it.

5.Change your repo’s remote URL to use SSH:

git remote set-url origin git@github.com:???/xxxx.git

6.Test it:

ssh -T git@github.com

7.Now git pull origin main and git push origin main will work without typing tokens.

STEP 4:
add some files

echo "# MESSAGE" >> README.md
git add README.md
git commit -m "first commit"

STEP 5:

git push -u origin master
  • Pushes your files to the remote repository.Git has a concept of something known as a “branch”, so by default everything is pushed to the master branch unless explicitly specified an alternate branch.
  • To know about the list of all branches you have in your repository type :git branch

some commands:

# delete a branch
git push origin --delete <branch name>

#show all remote and local branches
git branch -a

Leave a Reply

您的邮箱地址不会被公开。 必填项已用 * 标注

Related Post