Clone a repository, make a change and push it

Description: Clone the repository server.git into a folder my-work, add a file todo.txt, commit it and push it to the remote.

Hint:

  • A clone already has the remote origin, so a plain git push is enough.

Solution

Terminal output

$ git clone server.git my-work
Cloning into 'my-work'…
done.
$ cd my-work
$ echo "buy milk" > todo.txt
$ git add todo.txt
$ git commit -m "Add todo list"
[main 9eaf666] Add todo list
1 file changed, 1 insertion(+)
create mode 100644 todo.txt
$ git push
To /home/robin/server.git
4f5618b..9eaf666 main -> main

How it works

  • We used a local folder as the server. A GitHub URL works in the same way.
  • The last line shows that main was pushed to the remote main.

Read Git Clone and Git Push.


Learn more about the similar topics:
Tutorials
Git Clone
Git Remote
Git Push
Git Fetch and Pull
Exercises & Assignments
Clone a repository, make a change and push it
Get new changes from the remote with fetch and pull
Interview Questions & Answers
What is Git Clone and How to Clone a Git repository?
How can you push changes to a remote branch in Git?
What is the difference between git fetch and git pull?
What is the difference between git clone and fork?
What is origin in Git?
What is a pull request?
What is the difference between force push and force with lease in Git?