r/learnpython • • Sep 22 '20

What is learning GIT?

I saw in a post that you have to learn git for most programming jobs, what exactly is git? and where can i learn it, i always just assumed its just uploading your stuff to github. not too sure if this is the right place to post this

347 Upvotes

116 comments sorted by

View all comments

5

u/dieth Sep 22 '20

git is a at the very basic level a revision and transactional record keeping system.

Basics:

git init # initializes a new git repo in the current directory
git add filename # adds a file to the staging area
git commit -m "message" # records all the files into the staging area as a committed record
git log # see a list of all the commits
git status # see the state of the staging area and any other files that may have changed
git diff #see all your changes
git diff --name-only #see just the filenames you've changed

More fun:

git branch # list all of the branchs that exist
git branch newbranch # create a new branch for the current point you are at right now
git checkout branch # change to another branch
git blame filename # find our the username of every person who touched a line in a file in your current state

Getting into the power:

git push # Will push your latest commits to the origin if you pulled it from a github.com or other hosted git repo
git pull   # will pull down the latest commits from the project origin

Going crazy: # Both of these usually end up in Merge conflicts and I can only recommend a good IDE that handles Merge conflicts to best handle it.

git rebase branchname # Used when you branched off a main line that may have received updates since you've completed your task
git merge branchname # Used when you need to merge code from a completely separate branch