.txt
, .csv
, .py
, .c
, .R
, etc.) works best
Sourcetree | Git Kraken | Git Desktop |
---|---|---|
![]() |
![]() |
![]() |
PyCharm | RStudio | VS Code |
---|---|---|
![]() |
![]() |
![]() |
git config --global user.name "Me"
git config --global user.email "me@email.com"
git config --global core.editor "nano -w"
git config --list
user.name=Sam Mangham user.email=mangham@gmail.com core.editor=nano -w [plus much more on Windows]
ssh-keygen -t ed25519
cat ~/.ssh/id_ed25519.pub
Generating public/private ed25519 key pair. Enter file in which to save the key (/c/Users/Toaster/.ssh/id_ed25519): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/Toaster/.ssh/id_ed25519 Your public key has been saved in /c/Users/Toaster/.ssh/id_ed25519.pub The key fingerprint is: SHA256:<a long string> Toaster@Toast-Nova The key's randomart image is: <a square 'picture'>
ssh-keygen
climate-analysis
git clone git@github.com:yourname/climate-analysis
cd climate-analysis
ls -a
git status
git clone <your repo>
Cloning into 'climate-analysis'... remote: Enumerating objects: 4, done. remote: Counting objects: 100% (4/4), done. remote: Compressing objects: 100% (4/4), done. remote: Total 4 (delta 0), reused 3 (delta 0), pack-reused 0 (from 0) Receiving objects: 100% (4/4), done.
git status
# On branch main nothing to commit, working tree clean
:
)cd
to enter climate-analysis
nano README.md
Ctrl-O
then Enter
to save, Ctrl-X
to quitgit add README.md
git status
git commit -m "Your message"
git status
git add README.md
If you’re on Windows, you might see:
warning: in the working copy of 'README.md', LF will be replaced by CRLF the next time Git touches it
git commit -m "Your message"
[main 3347109] Added a basic readme file 1 file changed, 4 insertions(+) create mode 100644 README.md
git status
On branch main Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working directory clean
nano
(Ctrl-O
to save, Ctrl-X
to quit)git add README.md
-m
on commit (write your message in nano
)git log
git log
commit 334710937654821b3a89996c2c6af476548d28e9 (HEAD -> main) Author: Sam Mangham <mangham@gmail.com> Date: Wed Jan 8 18:40:04 2025 +0000 Added a basic readme file commit 3f6b071ef0d35af70793954adb00a3fc7fc7b949 (origin/main, origin/HEAD) Author: Sam Mangham <mangham@gmail.com> Date: Wed Jan 8 18:35:45 2025 +0000 Initial commit
nano climate_analysis.py
git diff
git add climate_analysis.py
git commit -m "Your message"
git diff
diff --git a/climate_analysis.py b/climate_analysis.py index 277d6c7..347c42b 100644 --- a/climate_analysis.py +++ b/climate_analysis.py @@ -1,3 +1,5 @@ +"""Tools for analysing climate data files""" + import sys import temp_conversion import signal
git commit
[main 0010185] Add docstring 1 file changed, 2 insertions(+)
nano
to edit climate_analysis.py
# TODO: Add rainfall processing code
” to the endnano climate_analysis.py
git diff
git add climate_analysis.py
git commit -m "Your message"
git log
git diff HEAD~1 climate_analysis.py
git diff HEAD~2 climate_analysis.py
git log
commit ed664c6d480f93829608791f3d8158f2dcab4107 (HEAD -> main) Author: Sam Mangham <mangham@gmail.com> Date: Thu Jan 9 10:11:27 2025 +0000 Added rainfall processing placeholder [3 more commits]
git diff HEAD~1 climate_analysis.py
diff --git a/climate_analysis.py b/climate_analysis.py index 347c42b..ce8ef32 100644 --- a/climate_analysis.py +++ b/climate_analysis.py @@ -27,3 +27,6 @@ for line in climate_data: kelvin = temp_conversion.fahr_to_kelvin(fahr) print(str(celsius)+", "+str(kelvin)) + +# TODO: Add rainfall processing code +
climate_analysis.py
since thengit log
git diff <COMMIT ID> climate_analysis.py
rm climate_analysis.py
git status
git restore climate_analysis.py
restore
doesn’t work, try checkout
git status
On branch main Your branch is ahead of 'origin/main' by 3 commits. (use "git push" to publish your local commits) Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) deleted: climate_analysis.py no changes added to commit (use "git add" and/or "git commit -a")
git checkout <COMMIT ID> climate_analysis.py
git push
git push
Counting objects: 11, done. Delta compression using up to 32 threads. Compressing objects: 100% (9/9), done. Writing objects: 100% (9/9), 1.11 KiB | 0 bytes/s, done. Total 9 (delta 2), reused 0 (delta 0) remote: Resolving deltas: 100% (2/2), completed with 1 local object. To git@github.com:smangham/climate-analysis 70bf8f3..501e88f main -> main
https
rather than ssh
Local:
nano README.md
git commit -am "Your message"
Remote:
README.md
to add install info to the endmain
git push
git push
To git@github.com:smangham/climate-analysis ! [rejected] main -> main (fetch first) error: failed to push some refs to 'git@github.com:smangham/climate-analysis' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first merge the remote changes (e.g., hint: 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
main
branches?git pull
git config pull.rebase false
if it failsnano README.md
and remove the <<<
/===
/>>>
git add README.md
git commit -am "Your message"
git push
git pull
remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From github.com:smangham/climate-analysis 501e88f..023f8f6 main -> origin/main Auto-merging README.md CONFLICT (content): Merge conflict in README.md Automatic merge failed; fix conflicts and then commit the result.
git branch
git branch dev
git switch dev
switch
doesn’t work, try checkout
git switch dev
Switched to branch `dev`
git switch dev
doesn’t work, try git checkout dev
nano rainfall_conversion.py
git add rainfall_conversion.py
git commit -m "Your message"
ls
git log
git switch main
ls
git log
git switch dev
git push origin dev
git config --global push.autoSetupRemote true
git push origin dev
Enumerating objects: 25, done. Counting objects: 100% (25/25), done. Delta compression using up to 20 threads Compressing objects: 100% (25/25), done. Writing objects: 100% (25/25), 4.40 KiB | 2.20 MiB/s, done. Total 25 (delta 6), reused 3 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (6/6), done. remote: remote: Create a pull request for 'dev' on GitHub by visiting: remote: https://github.com/smangham/climate-analysis/pull/new/dev remote: To github.com:smangham/climate-analysis * [new branch] dev -> dev
origin dev
main
not dev
git switch main
git merge dev
git switch dev
mkdir results
touch example.csv results/example.txt
git status
git status
On branch dev Your branch is up to date with 'origin/dev'. Untracked files: (use "git add <file>..." to include in what will be committed) example.csv results/example.txt nothing added to commit but untracked files present (use "git add" to track)
nano .gitignore
*.csv
and results/
git status
git add .gitignore
git commit -m "Your message"
git status
On branch dev Your branch is up to date with 'origin/dev'. Untracked files: (use "git add <file>..." to include in what will be committed) .gitignore nothing added to commit but untracked files present (use "git add" to track)