Git Commands
kjswis edytuje tę stronę 6 lat temu

Basic Commands

$ git status                         # Shows the current branch, and any file changes

$ git fetch --all                    # Looks for changes and new branches
$ git pull                           # Pulls changes from the server to your computer for the current branch

$ git add [files]                    # Adds the files to be saved (staged)
$ git commit                         # Commits the saved changes
$ git push origin [branch]           # Pushes changes from your computer to the server

when changes are commited, the terminal will open a commit file for you to insert a message. To insert, type i, then type your message and hit esc. You can then save your changes with :wq

To avoid using vi to edit your commit message, you can also alter your commit command

$ git commit -m 'my commit message'

Branches

Branches are a great way to keep changes contained, and avoid merge conflicts

$ git checkout [existing_branch]     # Switches to an existing branch
$ git checkout -b [new_branch]       # Creates a new branch based on the branch you were in

If you begin working on a branch, and changes get merged into master, you can rebase your branch to merge the changes more smoothy

$ git rebase master

If you want to clean up your branches, you can list and delete them

$ git branch                         # Lists all the local branches
$ git branch -D [branch]             # Deletes the specified branch locally