Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename file with Git

Tags:

git

github

I'm new to Git/Github and I needs some help. I would like to rename file from README to README.md. I have only one repo called "change-z-index".

1) I open and login like that:

ssh -T [email protected] 

And I enter my passphrase.

2) I try to rename the file like that:

git mv README README.md git commit -m "renamed" git push origin master 

It gives me an error saying bad source.

I think I need to select my repo first... it's name is "change-z-index". I have read manual many times, but still can't understand how to do it.

like image 484
Badr Hari Avatar asked Jul 31 '11 11:07

Badr Hari


People also ask

How do I rename a file in git bash?

Step 1: Open Git Bash. Step 2: Open the repository. Step 4: Use the “git status” command to check the changes. Step 5: Commit the renamed file.

How does git rename work?

Git keeps track of changes to files in the working directory of a repository by their name. When you move or rename a file, Git doesn't see that a file was moved; it sees that there's a file with a new filename, and the file with the old filename was deleted (even if the contents remain the same).


2 Answers

As far as I can tell, GitHub does not provide shell access, so I'm curious about how you managed to log in in the first place.

$ ssh -T [email protected] Hi username! You've successfully authenticated, but GitHub does not provide shell access. 

You have to clone your repository locally, make the change there, and push the change to GitHub.

$ git clone [email protected]:username/reponame.git $ cd reponame $ git mv README README.md $ git commit -m "renamed" $ git push origin master 
like image 174
hammar Avatar answered Oct 26 '22 23:10

hammar


Note that, from March 15th, 2013, you can move or rename a file directly from GitHub:

(you don't even need to clone that repo, git mv xx and git push back to GitHub!)

renaming

You can also move files to entirely new locations using just the filename field.
To navigate down into a folder, just type the name of the folder you want to move the file into followed by /.
The folder can be one that’s already part of your repository, or it can even be a brand-new folder that doesn’t exist yet!

moving

like image 22
VonC Avatar answered Oct 26 '22 23:10

VonC