Differences between revisions 13 and 14
Revision 13 as of 2022-08-22 13:50:16
Size: 3157
Editor: scot
Comment:
Revision 14 as of 2022-10-23 23:20:35
Size: 3169
Editor: scot
Comment:
Deletions are marked like this. Additions are marked like this.
Line 22: Line 22:
git remote add origin git@example.com:repos/my_project.git git remote add origin http://gitlab.scotnpatti.com/username/my_project

Starting a git repository?

First setup the remote repository:

ssh git@brain2.scotnpatti.com
cd /home/git/repos               # you shouldn't use the base user directory for good reasons -- See SshGen page
mkdir my_project.git
cd my_project.git
git init --bare
git update-server-info # If planning to serve via HTTP
exit

On your local machine:

cd [your project directory]
git init
git add * # or "." if you want to add all the files in the hierarchy
git commit -m "My initial commit message"
git remote add origin http://gitlab.scotnpatti.com/username/my_project
git push -u origin master

Others can now clone track the remote repository:

git clone git@example.com:repos/my_project.git
cd my_project

Adapted from: http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/

Standard workflow for private project (you only)

edit/stage/commit

git status # View the state of the repo
git add <some-file> # stage a file
git commit -m "message" # commits changes 

You can also add and commit in one statement

git commit -a -m "message"

Publish

git push origin master

GitHub Workflow

You found a project you want to contribute to.

  1. Fork the project (on git hub - now you should have a copy in your repository that is separate from the original)
  2. Clone it to your local file system. (i.e. git clone [url])
  3. Create a branch (i.e. git checkout -b [branchname])
  4. Edit files as needed
  5. Add/commit changes (i.e. Commit -a -m "Message")
  6. push to your forked git repository on github: git push origin [branchname]
  7. Check github for a link to a pull request. (Pull request link should be on code page see end of video).

See the video here

Dealing with Errors

If you are working with multiple people You may get an error when you commit or when you are merging your branch. In the first case it might look like this:

Updates were rejected because the tip of your current branch is behind its remote counterpart. Merge the remote changes (e.g. 'git pull') before pushing again.

So you may need to pull by doing the following:

git fetch origin master 
git merge origin master
git pull origin master

If you have changes, go edit the file to remove the conflicts (Visual Studio Code works great for this, better than Visual Studio 2017).

You may then get a CONFLICT (content): Merge conflict in <some-file> which you will need to resolve by type git status. Looking at the git status is a good idea for before you do anything.

Branches

So you started working on a program and realized that you should probably have started a branch. So,

git checkout -b [branchname]

... will create and checkout the new branch using the exiting code while leaving the old branch as is.

To switch to an existing branch leave off the -b. To switch to the previous branch do:

git checkout -

Viewing history

git log

ProjectManagementTools/StartingGitRepository (last edited 2023-06-06 19:32:34 by scot)