简体   繁体   中英

git how to do first commit after creating a repository

I work with git. I created a directory reflections4 and I copied a file in it. After this, I executed git init.

git log displays 

carlotavina (master #) reflections4 $ git log
fatal: your current branch 'master' does not have any commits yet

git status

carlotavina (master #) reflections4 $ git status
On branch master

No commits yet

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

    lesson_1_reflections.txt 

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

How can I display Initial commit in git status after creating a repository

You have not yet committed anything to the repository, only initialized one. From the documentation, linked below, init creates an empty repository, and does no population. Some services (github/lab, etc) will initialize the repository with a readme file or similar, which must be committed to be tracked. Manually running init does not do this.

You must add (commit) something to the empty repo it to see it. As such, if you git add lesson_1_reflections.txt and git commit -m "first commit" , you will than have a commit that you are able to look at.

If you are trying to sync with a remote repository (one hosted on another server, github, gitlab, bitbucket, etc.), there are additional steps you will have to take to make the two repositories (local and remote) talk to each other.

https://git-scm.com/docs/git-init

Step 1:

git add lesson_1_reflections.txt

Step 2:

git commit -m "<enter the desired commit message>"

Step 3 (after you set up a remote to push into):

git push

If prompted enter user and password

https://confluence.atlassian.com/bitbucketserver/basic-git-commands-776639767.html Lookout on this webpage you will find every information you want.

In your case, you have to add those files to your repository by

git add . // . means everything or "all"

git status // now you can see all the changes
git commit -m "Message that you want to send regarding this commit"
git push origin "whatever the branch name"(optional)

When you have empty repo. You can follow these steps for doing initial commit.

  1. Clone the empty repo. git clone <your git repo url>
  2. Now go to your repo using cd command and create a local branch say developement using command git checkout -b development
  3. We can now add some files in the repo echo "A new repo" > Readme
  4. Stage all the unstages files to commit git add.
  5. Show the staged files git status
  6. Commit the files to local git repo git commit -m "Adding readme file"
  7. Push the commit to your remote repo using git push -u origin development:development

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM