Python 3

home

Git Part II: Comitting Changes and Pushing to Server

Perform Your First Commit and Push

A "commit" adds a new file or changed file to the repo; "push" syncs the change with the server.


A. Modify the README.md text file to add to the repo. If the file was not created, please create one of this name here. Note the change or the text that you added to this file.
B. Add the new or updated file. Strangely, the add command refers to either newly added or changed files. When we 'add', we're really adding a change to the repo (whether a new or changed file).

(base) david@192 demo_20230808 % git add README.md

C. Commit and add the file
(base) david@192 demo_20230808 % git commit -m "first commit"
You'll see a message ackowledging the changes and the commit.

D. Push the changes to the github server.
(base) david@192 demo_20230808 % git push -u origin main
You'll see a series of messages indicating a warning (re: adding a RSA host)

Having successfully pushed a first file to the remote repository, your local folder is now connected and you can push changes remotely with git push at any time.

If you make a mistake initially and find you are having problems pushing, you can simply delete the local folder inside repos then delete the github repo by logging into github.com, clicking on the repository, choosing Settings, and scrolling down to "Delete this repository" at the bottom. (The entire repo including history of changes, comments, etc., will be deleted, so it should only be done to start from scratch.) Please follow the steps carefully and let me know if you have any problems -- thanks!





The git commit cycle: add or change file, commit, push

This cycle is repeated as we make changes and add these changes to git.


add or change a file (in this case I modified test-1.py)


git status to see that the file has changed

This command shows us the status of all files on our system:  modified but not staged, staged but committed and committed but not pushed.
(base) david@192 demo_20230808 %  git status
On branch main
Your branch is up-to-date with 'origin/main'.

Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

	modified:   test-1.py

no changes added to commit (use "git add" and/or "git commit -a")
(base) david@192 demo_20230808 %

git add the file (whether added or changed) to the staging area

(base) david@192 demo_20230808 %  git add test-1.py
(base) david@192 demo_20230808 %

git status to see that the file has been added

(base) david@192 demo_20230808 %  git status
On branch main
Your branch is up-to-date with 'origin/main'.

Changes to be committed:
  (use "git reset HEAD ..." to unstage)

	modified:   test-1.py

(base) david@192 demo_20230808 %

git commit the file to the local repository

(base) david@192 demo_20230808 %  git commit -m 'made a trivial change'
[main e6309c9] made a trivial change
 1 file changed, 4 insertions(+)
(base) david@192 demo_20230808 %

git status to see that the file has been committed, and that our local repository is now "one commit ahead" of the remote repository (known as origin

(base) david@192 demo_20230808 %  git status
# On branch main
# Your branch is ahead of 'origin/main' by 1 commit.
#

git pull to pull down any changes that have been made by other contributors

(base) david@192 demo_20230808 %  git pull
Already up-to-date.
(base) david@192 demo_20230808 %

git push to push local commit(s) to the remote repo

The remote repo in our case is github.com, although many companies choose to host their own private remote repository.
(base) david@192 demo_20230808 %  git push
Counting objects: 11, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 318 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
To https://github.com/NYU-Python/david-blaikie-solutions
   2ce8e49..e6309c9  main -> main
(base) david@192 demo_20230808 %

Once we've pushed changes, we should be able to see the changes on github.com (or our company's private remote repo).





[pr]