I guess in a way it makes sense because the local repository is also treated as a master, so you could first commit to the local repository and then push it to the remote repository/central repository.
But it's still really different from svn where no pushing is needed.
Git commands that I am learning for this sequence
ADD > COMMIT > PUSH
git add file
git commit -m "some message here"
git push origin master
Basic git commands
Make a local repository:
git init
OR
git init newdirectory
Add new files
git add filename
Add everything
git add ..
Commit a file version
git commit -m "Adding files"
Check files
git status
Commit all modified files without adding
git commit -a
With a message
git commit -a -m "some message"
Commit only specific files
git commit -m "change some files" file1 file2
Publish the repository
STEP 1: Make a "bare" repository, and upload it to a server.
cd /tmp
git clone --bare ~/your/repo/path project.git
scp -r project.git ssh://example.com/~/www/
Push commits to the server:
git push ssh://example.com/~/www/project.git
No need to type URL all the time - because git remembers the server of the clone
cd ..
git clone ssh://example.com/~/www/project.git project
git push
Can edit .git/config to add this address.
Get Upstream Changes and merge with the local repository
git pull
Pull from a specific place
git pull http://git.example.com/project.git
Looking into the log of commits
git log
Remove everything from a planned commit - without changing files
git reset HEAD
Remove
git rm file
Branching and Merging
git branch test
Checkout command to change branches.
git checkout test
The first branch, or main branch, is called "master."
git checkout master
Advanced Git
Switch back to master branch and merge
git checkout master
git merge test
And if you're done with the branch you can delete with the branch command and pass the -d flag.
git branch -d test
Traveling Through Time: Look at past versions
git checkout HASH
Uncommited changes will travel with you. Return to the preset with git checkout master as with normal branches. If you commit while in the past a branch is automatically created and your changes will have to be merged forward.
Sweeping Changes Under the Rug for Later
When moving between branches your local changes move with you. Sometimes you want to switch branches but not commit or take those changes with you. The Git command stash lets you put changes into a safe store.
git stash
You can retreive by passing an arguement of apply or pop.
git stash apply
The difference between apply and pop is simple. apply will take a stash state and apply it, but preserve that state in the stash. pop will take the stash state, apply it, and remove it from the stash. git stash clear empties the contents of the stash.
0 Comments:
Post a Comment