0% found this document useful (0 votes)
5 views2 pages

Github Commands Guide

github

Uploaded by

gdemagv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Github Commands Guide

github

Uploaded by

gdemagv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Here's an explanation of how each command works:

### Create a new repository on the command line

1. **`echo "# my_notes" >> README.md`**

- Appends the text `# my_notes` to a file named `README.md`. If the file doesn't
exist, it creates one.

2. **`git init`**

- Initializes a new Git repository in the current directory. Creates a hidden


`.git` folder to track changes.

3. **`git add .`**

- Stages all changes (new files, modifications, deletions) in the current


directory for the next commit.

4. **`git add README.md`**

- Stages only the `README.md` file for the next commit. This is redundant if you
already ran `git add .`.

5. **`git commit -m "first commit"`**

- Creates a commit with the staged changes, including a message (`"first


commit"`) describing what was changed.

6. **`git branch -M main`**

- Renames the current branch to `main`. This is often done to follow modern
naming conventions.

7. **`git remote add origin https://github.com/linkOfyourRepositery`**

- Links your local Git repository to a remote repository hosted on GitHub at the
given URL.

8. **`git push -u origin main`**

- Pushes the `main` branch to the remote repository (`origin`) and sets
`origin/main` as the default upstream branch for future pushes and pulls.

---

### Push an existing repository to a remote

1. **`git remote add origin https://github.com/kashershahzad/my_notes.git`**

- Links the local repository to the GitHub repository at the specified URL
(`https://github.com/kashershahzad/my_notes.git`).

2. **`git branch -M main`**

- Renames the current branch to `main`.

3. **`git push -u origin main`**


- Pushes the current branch (`main`) to the remote repository (`origin`) and
sets it as the default upstream branch for future operations.

### Pull an existing repository to a remote

git pull origin main


Fetches updates from the remote repository's main branch and merges them into the
local main branch.

You might also like