0

I usually does the following with

$ mv file1.py file2.py
$ git add .
$ git rm file1.py

How can I skip the last step? So that whenever I add the newly name files it will automatically remove the old one file1.py in the git repository.

I know I can do git mv file1.py file2.py. But in my workflow I tend to do many mv commands and prefer to add and commit them at the very end.

neversaint
  • 60,904
  • 137
  • 310
  • 477

1 Answers1

2

If you want to stage all current files you can do it with git add -u So you can try the following combination:

git add . #add new files
git add -u #stage removed files

Example

lol4t0@lol4t0-VirtualBox:~/gtets$ mv foo bar
lol4t0@lol4t0-VirtualBox:~/gtets$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

  deleted:    foo

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

  bar

no changes added to commit (use "git add" and/or "git commit -a")
lol4t0@lol4t0-VirtualBox:~/gtets$ git add -u
lol4t0@lol4t0-VirtualBox:~/gtets$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

  deleted:    foo

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

  bar

lol4t0@lol4t0-VirtualBox:~/gtets$ git add .
lol4t0@lol4t0-VirtualBox:~/gtets$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

  renamed:    foo -> bar
Lol4t0
  • 12,444
  • 4
  • 29
  • 65