How to Manage your GIT Repository Tutorial

GIT Repository Management

This tutorial explains how to use GIT to create a project, add files, commit modifications and upload them in the remote repository at GitHub.

First, you should generate an SSH key. You must have at least one SSH public key to push your git repository to GitHub.

You can check our knowledgebase articles how to generate an SSH key in WindowsMAC OS and Linux.

Next, you should add the key through the GitHub interface. This is done by accessing the Settings page for your account -> SSH and GPG Keys section. On that page, click the New SSH key button.

A new panel will appear in which you should input a Title for the key and the private key itself. Once done, press the Add SSH key button.

Then, open a new Terminal window on your computer. First you should create a new folder in which to develop and manage the repository. This can be done with the following command:

1

user@user [~]# mkdir GIT

This will create a folder named GIT in the current working directory. Access that folder with:

1

user@user [~]# cd GIT

Then initialize a new GIT repository with:

1

2

user@user [~/GIT]# git init

Initialized empty Git repository in /home/username/GIT/.git/

You should create files and folders for your GIT repository. For example, you can create a README file with the following command:

1

user@user [~/GIT]# touch README

This will create an empty file named README in the GIT repository folder. However this does not automatically add the file to the GIT repo. You can compare the list of files in the actual GIT repository and the list of current files you have created with:

1

2

3

4

5

6

7

8

9

10

11

user@user [~/GIT]# git status

On branch master

Initial commit

Untracked files:

(use "git add <file>..." to include in what will be committed)

README

nothing added to commit but untracked files present (use "git add" to track)

The above shows that you have a file named README that is present in the folder, but is not added to GIT repository. So now, you need to add the file to the GIT repository index. This can be done with:

1

user@user [~/GIT]# git add README

Then, you can compare again the list of files in the actual GIT repository and the list of current files you have created:

1

2

3

4

5

6

7

8

9

user@user [~/GIT]# git status

On branch master

Initial commit

Changes to be committed:

(use "git rm --cached <file>..." to unstage)

new file:   README

The file is now added to the repo index and you need to commit it. By committing a file, you add it to the actual repository. Committing is used when you create new files or modify existing ones and want to "push" your changes to the repository. To commit the README file, you can use the following command:

1

2

3

4

5

user@user [~/GIT]# git commit -m ‘first commit‘

[master (root-commit) e2a16e0] first commit

1 file changed, 0 insertions(+), 0 deletions(-)

create mode 100644 README

where "-m ‘first commit‘" is a comment which is left in the repository history. Using commits you can describe the changes which are made to the repository files, which will help you better to follow the development of your project.

Now,  if you check the status of the git repository, you will see there are no new changes to commit.

1

2

3

4

user@user [~/GIT]# git status

On branch master

nothing to commit, working directory clean

All of these changes were done to a local repository on your machine. If you want to push them to the remote GIT repo you have at GitHub, you first need to add the repo on your machine with:

1

user@user [~/GIT]# git remote add origin [email protected]:your_username/name_of_your_repo.git

Make sure to replace your_username and name_of_your_repo with your actual GitHub username and the name of your repository. The command will "link" the two repositories, so any changes made to the local one can be pushed to the remote one at GitHub.

To push the changes to the GitHub repository now, you can use this command:

1

2

3

4

5

user@user [~/GIT]# git push origin master

Counting objects: 3, done.

Writing objects: 100% (3/3), 207 bytes, done. Total 3 (delta 0),

reused 0 (delta 0) To git@github.com:user/test.git * [new branch] master -> master

Now, if you access the GitHub repository, you will see the README file there.

原文地址:https://www.cnblogs.com/karmapeng/p/12179425.html

时间: 2024-10-12 03:32:15

How to Manage your GIT Repository Tutorial的相关文章

Start a GIT Repository Tutorial

Start a GIT Repository The first step in creating a GIT repository is finding where to actually create it. You can either create the repository on your hosting account or use a remote GIT repository service. If you decide to use your hosting account,

git: fatal: Not a git repository (or any of the parent directories): .git

在看书 FlaskWeb开发:基于Python的Web应用开发实战 时,下载完源码后 git clone https://github.com/miguelgrinberg/flasky.git 试着 切换到 提交历史 1a, $ git checkout 1a,出现error: fatal: Not a git repository (or any of the parent directories): .git 这个提示表明现在不在一个git repository目录下,需要切换到flask

把Git Repository建到U盘上去

Git很火.原因有三: 它是大神Linus Torvalds的作品,天然地具备神二代的气质和品质: 促进了生产力的发展,Git的分布式版本控制理念,并非首创,但非常适合开源社区的协作方式(不存在master-slave的关系) GitHub GitHub很好,号称代码界的facebook. facebook,twitter,Microsoft,vmware,redhat,LinkedIn,Yahoo等公司都在GitHub上有建立数目不等的repositories.一些知名开源项目,例如jQuer

解决:fatal: Not a git repository (or any of the parent directories): .git

fatal: Not a git repository (or any of the parent directories): .git 在用个git上传android项目时发现 git add file添加文件时出现这样错误: fatal: Not a git repository (or any of the parent directories): .git 提示说没有.git这样一个目录,解决办法如下: 接着在下一行直接输入git init就可以了!

新目录下使用git管理,未配置.git目录,报错fatal: Not a git repository (or any of the parent directories): .git

fatal: Not a git repository (or any of the parent directories): .git 第一次用Git,遇到这个错误提示,原来是这样的: fatal: Not a git repository (or any of the parent directories): .git This tells you that the directory you're in is not a git repository. Before you can add

git 解决fatal: Not a git repository

我用 git remote add origin [email protected]:michaelliao/learngit.git 添加远程库时提示: fatal: Not a git repository (or any of the parent directories): .git 提示说没有.git这样一个目录, 解决办法如下: 当时发现自己所在目录并非git初始化库目录,所以跳转到git库,重新运行ok;

getting “fatal: not a git repository: &#39;.&#39;” when using post-update hook to execute &#39;git pull&#39; on another repo

Here is the script that ultimately worked. I think the bit I was originally missing that prevented it from working remotely was the unset GIT_DIR #!/bin/shcd /path/to/working-copy/ || exitunset GIT_DIRgit pull repo branch exec git-update-server-info

把Git Repository建到U盘上去(转)

把Git Repository建到U盘上去 转 把Git Repository建到U盘上去 Git很火.原因有三: 它是大神Linus Torvalds的作品,天然地具备神二代的气质和品质: 促进了生产力的发展,Git的分布式版本控制理念,并非首创,但非常适合开源社区的协作方式(不存在master-slave的关系) GitHub GitHub很好,号称代码界的facebook. facebook,twitter,Microsoft,vmware,redhat,LinkedIn,Yahoo等公司

Git CMD - init: Create an empty Git repository or reinitialize an existing one

命令格式 git init [-q | --quiet] [--bare] [--template=<template_directory>] [--separate-git-dir <git dir>] [--shared[=<permissions>]] [directory] 命令参数 --quiet, -q 安静模式,只打印错误和警告信息. 实例 a) 创建版本库 [[email protected] git]$ mkdir hello_git [[email