This repo has been prepared as the platform to practice git commands.
It is perfectly ok to break things.
- Check to see if you have git installed: https://github.com/git-guides/install-git
- Although not required, it is recommended to enable SSH authentication: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account
-
cloneUse this command to clone an existing repo. To clone this repo,
git clone https://github.com/CADWRDeltaModeling/test.gitTo change the name of the directory (e.g., "github_exercises"),
git clone https://github.com/CADWRDeltaModeling/test.git github_exercises -
initUse this to create a new git repo. For example, running
git initwill make the current directory a git repo. -
statusThis shows the status of the local repo - any changes, what have been staged, etc.
Frequently used options:
-s-u[mode]: Specifies what is displayed under "Untracked files".-umust be followed by one of the following modes without any space (e.g.,git status -uno):no: Hides untracked files.all: Shows all untracked files. Same as runninggit status -u.normal: Shows untracked files and the names of directories that contain untracked files (without the contents therein). Same as runninggit status(without the-uoption).
Note: git tracks files, not directories. Thus, empty directories will never show up with `git status` -
addThis command stages the changes that have occurred in the local repo (modifying what is inside a file, creating a new file, removing an exsting file, etc. ).
Frequently used options:
-i: Enters interactive mode. Here, user can select deisred commands step by step.-p: Pick and choose different edits and files -
commitCommits currently staged changes.
Frequently used options:
-m: Used as ingit commit -m "Introduce a new variable x", this option lets users to provide the commit message directly (as opposed to entering it on the default text editor)--amend: Whengit commit --amendis run, user can change the last commit message. -
pushPushes all commited changes to the remote repo.
-
pullFetches new commits from the remote repo then merges them into the local (same thing as doing
git fetchthengit merge).Frequently used options:
--rebase(strongly recommended to use whenver doinggit pull): Fetches new commits from the remote, then combines them with any local changes without merging, thus creating a clean, linear history. -
resetUndos commits that have not been pushed to the remote repo.
Frequently used options:
--soft: Only moves the HEAD, and all commited changes are saved.--mixed: Moves the HEAD and and unstages changes, but the working directory is NOT modified. Default behavior ofgit reset(used without options)--hard: The working directory becomes exactly the selected commit. To undo, rungit reflogto identify the point to which you want to go back, then rungit resetfollowed by the reference hash.
-
mv: Renames or moves a file then automatically stages the changes. -
rm: Removes a file then automatically stages the changes. -
restore: Discards uncommited changes. -
stash: Temporarily shelves the local changes to be used later.Use example:
- Run
git stashto shelve local changes. - Run
git stash listto look at the list of stashes. - Run
git stash applyfollowed by the stash hash to bring back the desired changes. - Run
git stash popapplies and removes the stash.
- Run
-
tag: Marks specific commits.Use example:
- Run
git tag v1to mark the current commit as "v1" - Run
git tagto see list of existing tags - Run
git show v1to see what the tagged commit changed. If a message was included when tagging (e.g.,git tag -a v1 -m "Prototype done"), then the message will also be shown.
- Run
branchcheckouttrackupdate
- fork
- pull request
- squash
- reorder
- delete
Conflict resolution is confusing in vscode so might be simpler to do via plain text editor Look for
<<<<<<
some words here
======
some other words here
>>>>>>
Resolve the above by choosing any combination of the text between <<<<< and >>>>> and then removing those special markers <<<<<<<<, =========, >>>>>>>> once done
E.g. I typed in whatever content and replaced the special markers
some words here with other words that are upto me
Make sure to verify that there are no other conflict blocks (with those special symbols anywhere else)
Then add the modified file and commit as usual to resolve the merge.
