Hướng dẫn add source vào repository trên github

If your code is stored locally on your computer and is tracked by Git or not tracked by any version control system (VCS), you can import the code to GitHub using GitHub CLI or Git commands.

Show
    • Mac
    • Windows
    • Linux

    If you have source code stored locally on your computer that is tracked by Git or not tracked by any version control system (VCS), you can add the code to GitHub by typing commands in a terminal. You can do this by typing Git commands directly, or by using GitHub CLI.

    GitHub CLI is an open source tool for using GitHub from your computer's command line. GitHub CLI can simplify the process of adding an existing project to GitHub using the command line. To learn more about GitHub CLI, see "About GitHub CLI."

    If your source code is tracked by a different VCS, such as Mercurial, Subversion, or Team Foundation Version Control, you must convert the repository to Git before you can add the project to GitHub.

    • "Importing a Subversion repository"
    • "Importing a Mercurial repository"
    • "Importing a Team Foundation Version Control repository"

    Warning: Never git add, commit, or push sensitive information to a remote repository. Sensitive information can include, but is not limited to:

    • Passwords
    • SSH keys
    • AWS access keys
    • API keys
    • Credit card numbers
    • PIN numbers

    For more information, see "Removing sensitive data from a repository."

    If your locally-hosted code isn't tracked by any VCS, the first step is to initialize a Git repository. If your project is already tracked by Git, skip to "."

    1. Open TerminalTerminalGit Bash.
    2. Navigate to the root directory of your project.
    3. Initialize the local directory as a Git repository. By default, the initial branch is called main. If you’re using Git 2.28.0 or a later version, you can set the name of the default branch using -b.

      git init -b main

      If you’re using Git 2.27.1 or an earlier version, you can set the name of the default branch using git symbolic-ref.

      git init && git symbolic-ref HEAD refs/heads/main

    4. Add the files in your new local repository. This stages them for the first commit.

      $ git add .

      Adds the files in the local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.

    5. Commit the files that you've staged in your local repository.

      $ git commit -m "First commit"

      Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.

    After you've initialized a Git repository, you can push the repository to GitHub, using either GitHub CLI or Git.

    • ""
    • ""

    1. To create a repository for your project on GitHub, use the

      git init && git symbolic-ref HEAD refs/heads/main

      0 subcommand. When prompted, select Push an existing local repository to GitHub and enter the desired name for your repository. If you want your project to belong to an organization instead of your user account, specify the organization name and project name with

      git init && git symbolic-ref HEAD refs/heads/main

      1.
    2. Follow the interactive prompts. To add the remote and push the repository, confirm yes when asked to add the remote and push the commits to the current branch.
    3. Alternatively, to skip all the prompts, supply the path to the repository with the

      git init && git symbolic-ref HEAD refs/heads/main

      2 flag and pass a visibility flag (

      git init && git symbolic-ref HEAD refs/heads/main

      3,

      git init && git symbolic-ref HEAD refs/heads/main

      4, or

      git init && git symbolic-ref HEAD refs/heads/main

      5). For example,

      git init && git symbolic-ref HEAD refs/heads/main

      6. Specify a remote with the

      git init && git symbolic-ref HEAD refs/heads/main

      7 flag. To push your commits, pass the

      git init && git symbolic-ref HEAD refs/heads/main

      8 flag. For more information about possible arguments, see the GitHub CLI manual.

    Before you can add your local repository to GitHub using Git, you must authenticate to GitHub on the command line. For more information, see "."