-
Notifications
You must be signed in to change notification settings - Fork 0
git basic
Michael Kramer edited this page Feb 8, 2019
·
7 revisions
-
git checkout -b branch-name
This will checkout a new branch with that name. -
git add ./
This stages all files that you touched for the next commit. The./
means all -
git commit -m 'Your amazing message'
This is the commit command. -
git push --set-upstream origin branch-name
This pushes your branch to the remote.
git remote prune origin
git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'/`; do git branch -D $branch; done
This website gives a good explanation of what this does. http://erikaybar.name/git-deleting-old-local-branches/
Lets say you created a group of files it started off small but has grown, so you want to move all of them to a new folder to keep things organized. Yet you can't just move it because other people on your team are editing those same files in their branches.
git mv file new_location/file
Why would you not just move it in the folder structure?
So, without git rm, one might do (this is Unix/OSX but the steps are similar in windows unless using cygwin terminal emulator and then u probably can):
$ mv newfile movedfile
$ 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: newfile
Untracked files:
(use "git add <file>..." to include in what will be committed)
movedfile
no changes added to commit (use "git add" and/or "git commit -a")
$ git rm newfile
rm 'newfile'
$ git add movedfile
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: newfile -> movedfile
$ git commit -m"renamed"
[master 46332e4] renamed
1 file changed, 0 insertions(+), 0 deletions(-)
rename newfile => movedfile (100%)
$ git status
On branch master
nothing to commit, working directory clean
whereas with git rm one can just do:
$ git mv newfile2 renamed_newfile2
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: newfile2 -> renamed_newfile2
$ git commit -m"renamed"
[master 8d1e296] renamed
1 file changed, 0 insertions(+), 0 deletions(-)
rename newfile2 => renamed_newfile2 (100%)
$ git status
On branch master
nothing to commit, working directory clean
git checkout 97815003a489d9c66a5d5866c1eba25de0575e9e -- crons.js