Use Cases
Classic git use cases
Use Case #1 : Git clone someone else's repository & Git push to your own repository
-
Create a new repository at github.com. (this is your repository)
Give it the same name as the other repository.
Don't initialize it with a README, .gitignore, or license. -
Clone the other repository to your local machine. (if you haven't done so already)
git clone https://github.com/other-account/other-repository.git
-
Rename the local repository's current 'origin' to 'upstream'.
git remote rename origin upstream
-
Give the local repository an 'origin' that points to your repository.
git remote add origin https://github.com/your-account/your-repository.git
-
Push the local repository to your repository on github.
git push origin master
-
Create a new repository at github.com. (this is your repository)
Give it the same name as the other repository.
Don't initialize it with a README, .gitignore, or license. -
Clone the other repository to your local machine. (if you haven't done so already)
git clone https://github.com/other-account/other-repository.git
-
Change the local repository's current 'origin' to a new url.
git remote set-url origin http://github.com/YOU/YOUR_REPO
-
Push the local repository to your repository on github.
git push origin master
Use Case #2 : Undo last git push
Use Case #3 : Move git folder to child folder
-
Manually move your .git folder to the place you want it (target_dir)
-
Navigate to that folder
-
Then add all the changes to the staging area. Git will detect these files as renamed versions of old files that were 'lost' and so no history will be lost.
-
Commit all the changes with the -a command. The -a command stands for all. It tells the commit command to automatically stage files that have been modified and deleted whilst new files that you have not told Git about are not affected.
-
Finally, push the changes to your repo.
Warning
You may receive the following git merge error message: "Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch"
To solve this:
1 2 3 4 5 |
|
You will then to git push again and you're done!
Use Case #4 : Duplicate a repo
-
Move to a scratch dir
-
Make a bare clone of the repository
-
Mirror-push to the new repository
-
Manually delete the old "foo" folder