-
Notifications
You must be signed in to change notification settings - Fork 0
Git Cheatsheet
Matt Church edited this page Apr 18, 2024
·
1 revision
A very bare-bones sample git workflow for the command line - for those moments when you just can't remember that one thing!
- Create the repo on Github
- Copy the https clone URL under the code download dropdown:
- Navigate to the directory where you want the repo to live on your machine
- Clone the repo using
git clone paste_clone_url_here
- Navigate into the newly created repo directory with
cd reponame
- Set up the .gitignore file using
nano .gitignore
on Mac or Linux, andnotepad .gitignore
on Windows - Commit and push your changes to establish the connection between your local copy of the repo and the online one (called the "remote")
Creates a snapshot of the status of every tracked file in the repo
-
git add --all
- tells git to track any newly-added files git commit -m "Some useful message about what changes are contained in this commit"
-
git push
- uploads your changes to the remote repo (i.e. on Github)
To do new work without messing up working code on another branch
-
git branch branchname
- make a new branch locally -
git checkout branchname
- switch to editing the new branch (these two commands can be accomplished with the shortcut:git checkout -b branchname
) - Commit (
push
will fail because the branch isn't yet linked to any corresponding branch on the remote) - do point 4: -
git push -u origin branchname
- shorthand forgit push --set-upstream origin branchname
; sets the remote branch which the local should interface with.origin
is the remote name
To merge finished, working code into another branch
- Make sure all changes on both involved branches are committed and pushed - use
git status
to check -
git checkout receivingbranch
- merge is a "receiving" operation -
git merge otherbranch
- merges changes intoreceivingbranch
git push
Delete a branch once it's merged to avoid clutter abnd confusion
-
git push -d origin branchname
- delete the branch on the remote -
git branch -d branchname
- delete the local copy