Here are some helpful hints and tips when working with git.
The below is a curl request you can run from the command line. Just change the user and add the name:
curl -u ‘USERNAME’ https://api.github.com/user/repos -d '{"name”:”REPONAME”}’
Set the remote to the repo on github (add the username sometimes):
git remote add origin https://karava@github.com/karava/testCommandLineCreation.git
check the url of the origin:
git remote get-url origin
Reference: https://help.github.com/en/articles/adding-an-existing-project-to-github-using-the-command-line
Fetch repos using this:
curl https://api.github.com/users/karava/repos | grep -w '"name"'
Alternatively here is a tool that can be used to fetch repositories, submit pull requests, fork repos all from the command-line https://hub.github.com. What are the advantages of git command line tools:
Some general tips:
Questions:
How can you search commits/view commit history, or search view/merge history. For example if you want to go back in time and find out what was done, or what broke what? Or to find how some old code was implemented, or to find some code that was deleted. In particularly how would you find when code you deleted still lived in git?
git clone {url}git fork - creates your own copy of a repogit add (*)git diffgit difftoolgit commitgit commit -am “message” - Will add all the files you have changed and commit them together in one step. My question is what about if you have added new files?git commit -m “sfsf” -m “dsfsd” - First message is title, second message is descriptiongit statusgit pushgit push origin master - Meaning push these changes to the master branchgit pullgit log - will give history of all the commits made previously and their messagesgit reset --soft HEAD~1 - undo last commit. You may need to do a force push, if you pushed the last commitgit reset --hard [commit] - rollback and go back to an older versiongit reset — hard origin/master - go back to the latest branch in the git repogit revert [commit] - revert performs an operation that inverses the changes of a specific commit and then creates a commit stating that it did this reversiongit rm --cached {file} - remove file from git repo but keep on disk, don't forget to push, and use -r for recursive in multiple files in a foldergit checkout -- :/ discard all changes in repo
get picture from slides fix merge conflicts, usually keep yours or theirs? then commit the change the message will usually be “fixed merge conflicts” then git push
A Branch is a version of the repo. Each branch has its own commit history and current version
git branch - shows all branches of codegit branch {branch_name} - create a new branch. This does not check out the new branch.git branch -D {branch_name} - delete branchgit checkoutgit checkout -b {branch_name} - both creates and check-out a new branch at the same timegit merge {branch_name} - switch to master branch and then run this commandgit remote prune origin - This gets rid of all the local repository branches that are not on the origingit branch -vv | grep gone - Useful command to use when cleaning branches
Delete all pruned branches all in one useful command. Inspired by and explained in this post.
git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -d